using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Windows.Forms;
using FlexCell;
using Infragistics.UltraChart.Data.Series;
using Infragistics.UltraChart.Resources.Appearance;
using Infragistics.UltraChart.Shared.Styles;
using Infragistics.Win;
using Infragistics.Win.UltraWinChart;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinScrollBar;
using Infragistics.Win.UltraWinTabControl;
using Infragistics.Win.UltraWinTabs;
using PluginFrame;
using static FlexCell.Grid;

namespace PcrExperimentProject
{
    public class PcrExperimentProjectService : IPlugin, IProvideService, IPcrExperimentProjectService
    {
        protected ResourceManager mResourceManager;

        private IApplication mApplication;

        private string mName = "";

        private string mDescription = "";

        private IConfigurationService mConfigurationService;

        private IPcrOptionService mPcrOptionService;

        private IPcrProgramConfiguration mPcrProgramConfiguration;

        private IPcrLogService mPcrLogService;

        private IMiscService mMiscService;

        private IPcrSystemService mPcrSystemService;

        private FormProjectEditor mProjectEditor;

        private IRuleEditorService mRuleEditorService;

        private bool mIsItemGridEnterKeyUp;

        private int mIndex;

        public int Index
        {
            get
            {
                return mIndex;
            }
            set
            {
                mIndex = value;
            }
        }

        public IApplication Application
        {
            get
            {
                return mApplication;
            }
            set
            {
                mApplication = value;
            }
        }

        public string Name
        {
            get
            {
                return mName;
            }
            set
            {
                mName = value;
            }
        }

        public string Description
        {
            get
            {
                return mDescription;
            }
            set
            {
                mDescription = value;
            }
        }

        public event EventHandler<EventArgs> PluginEvent;

        public void Execute(object[] context)
        {
        }

        public void UnLoad()
        {
        }

        public object ProvideService()
        {
            return null;
        }

        public void Load()
        {
            try
            {
                if (mApplication != null)
                {
                    mApplication.AddService(mName, this);
                    mConfigurationService = (IConfigurationService)mApplication.GetService("ConfigurationService");
                    mMiscService = (IMiscService)mApplication.GetService("MiscService");
                    mPcrSystemService = (IPcrSystemService)mApplication.GetService("PcrSystemService");
                    mPcrProgramConfiguration = mConfigurationService.PcrProgramConfiguration;
                    mPcrLogService = (IPcrLogService)mApplication.GetService("PcrLogService");
                    mPcrOptionService = (IPcrOptionService)mApplication.GetService("PcrOptionService");
                    mRuleEditorService = (IRuleEditorService)mApplication.GetService("RuleEditorService");
                    mResourceManager = ResourceManager.CreateFileBasedResourceManager("PcrExperimentProject", mApplication.GetResourceFolder() + GetType().Namespace + "\\", null);
                }
                InitializeMenu();
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        private void menuProjectManager_Click(object sender, EventArgs e)
        {
            try
            {
                mApplication.SetCursor(Cursors.WaitCursor);
                LoadExperimentProjectManager();
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
            finally
            {
                mApplication.SetCursor(Cursors.Default);
            }
        }

        private void menuCreateProject_Click(object sender, EventArgs e)
        {
            try
            {
                mApplication.SetCursor(Cursors.WaitCursor);
                LoadNewExperimentProjectEditor(mConfigurationService.DefaultProjectType);
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
            finally
            {
                mApplication.SetCursor(Cursors.Default);
            }
        }

        private void menuEditProject_Click(object sender, EventArgs e)
        {
            try
            {
                string text = LoadProjectFileDialog(mPcrSystemService.GetActiveFormProjectFolder(null), string.Empty);
                mApplication.SetCursor(Cursors.WaitCursor);
                if (!string.IsNullOrEmpty(text))
                {
                    LoadExperimentProjectEditor(text, true);
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
            finally
            {
                mApplication.SetCursor(Cursors.Default);
            }
        }

        private void menuLoadProject_Click(object sender, EventArgs e)
        {
            try
            {
                mPcrSystemService.LoadPcrProgramToActiveExperimentInPcrForm(true);
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        private string LoadProjectFileDialog(string initialDirectory, string fileName)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (!Directory.Exists(initialDirectory))
            {
                initialDirectory = mApplication.GetAssemblyPath() + mConfigurationService.ProjectFileDefaultFolder;
            }
            openFileDialog.InitialDirectory = initialDirectory;
            openFileDialog.Multiselect = false;
            openFileDialog.Filter = "Project file(*.prj)|*.prj";
            openFileDialog.DefaultExt = ".prj";
            openFileDialog.FileName = fileName;
            openFileDialog.Title = mResourceManager.GetString("OpenProjectFile");
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                return openFileDialog.FileName;
            }
            return string.Empty;
        }

        public bool ChooseProjectFromManager(ref IPcrExperimentProject cellProject, IPcrExperimentProject defaultProject, IChannelConfiguration[] channelConfiguration, PcrSystemType systemType, IPcrExperiment pcrExperiment)
        {
            FormChooseProjectFromManager formChooseProjectFromManager = new FormChooseProjectFromManager(mApplication, ref cellProject, defaultProject, channelConfiguration, systemType, pcrExperiment);
            formChooseProjectFromManager.ShowDialog();
            if (formChooseProjectFromManager.IsReturnConfirm)
            {
                cellProject = formChooseProjectFromManager.PcrExperimentProject;
            }
            return formChooseProjectFromManager.IsReturnConfirm;
        }

        public void LoadProjectAnalysisParametersOption(List<IPcrExperimentProject> projects, PcrSystemType systemType, bool isShowAutoAnalysis)
        {
            if (systemType.Equals(PcrSystemType.AbsoluteAnalysis))
            {
                AbsoluteAnalysisParameters absoluteAnalysisParameters = new AbsoluteAnalysisParameters(mApplication, projects, isShowAutoAnalysis);
                absoluteAnalysisParameters.ShowDialog();
            }
        }

        public void LoadExperimentProjectManager()
        {
            FormProjectManager formProjectManager = new FormProjectManager(mApplication);
            formProjectManager.ShowDialog();
        }

        public IPcrExperimentProject OpenPcrExperimentProject()
        {
            string text = LoadProjectFileDialog(mPcrSystemService.GetActiveFormProjectFolder(null), string.Empty);
            if (!string.IsNullOrEmpty(text))
            {
                return LoadExperimentProjectFile(text);
            }
            return null;
        }

        public string LoadExperimentProjectEditor(string projectFileName, bool isAllowToChangeChannelSettings)
        {
            IPcrExperimentProject pcrExperimentProject = null;
            pcrExperimentProject = ((!string.IsNullOrEmpty(projectFileName)) ? LoadExperimentProjectFile(projectFileName) : CreateNewEmptyProject());
            return LoadExperimentProjectEditor(pcrExperimentProject, isAllowToChangeChannelSettings, false, false);
        }

        public string EditExperimentProjectProgram(IPcrExperimentProject pcrExperimentProject)
        {
            if (pcrExperimentProject == null)
            {
                return string.Empty;
            }
            return LoadExperimentProjectEditor(pcrExperimentProject, false, true, false);
        }

        public void CheckProjectPasswordMatch(IPcrExperimentProject pcrExperimentProject)
        {
            if (!string.IsNullOrEmpty(pcrExperimentProject.Password))
            {
                pcrExperimentProject.IsPasswordMatch = mPcrOptionService.ShowExperimentEncryptionCheck(pcrExperimentProject.Password, mResourceManager.GetString("InputProjectPasswordString") + ":" + pcrExperimentProject.Name);
            }
            else
            {
                pcrExperimentProject.IsPasswordMatch = true;
            }
        }

        public string LoadExperimentProjectEditor(IPcrExperimentProject pcrExperimentProject, bool isAllowToChangeChannelSettings, bool isOnlyEditProgram, bool isNewProject)
        {
            string result = string.Empty;
            mApplication.SetCursor(Cursors.WaitCursor);
            if (mProjectEditor == null)
            {
                CheckProjectPasswordMatch(pcrExperimentProject);
                if (isOnlyEditProgram)
                {
                    if (pcrExperimentProject.SystemType == PcrSystemType.AbsoluteAnalysis)
                    {
                        mProjectEditor = new FormProgramEditor(mApplication, pcrExperimentProject, isNewProject, isAllowToChangeChannelSettings);
                    }
                    else if (pcrExperimentProject.SystemType == PcrSystemType.Allele)
                    {
                        mProjectEditor = new FormAlleleProgramEditor(mApplication, pcrExperimentProject, isNewProject, isAllowToChangeChannelSettings);
                    }
                    else if (pcrExperimentProject.SystemType == PcrSystemType.GeneScan)
                    {
                        mProjectEditor = new FormGeneScanProgramEditor(mApplication, pcrExperimentProject, isNewProject, isAllowToChangeChannelSettings);
                    }
                }
                else if (pcrExperimentProject.SystemType == PcrSystemType.AbsoluteAnalysis)
                {
                    mProjectEditor = new FormProjectEditor(mApplication, pcrExperimentProject, isNewProject, isAllowToChangeChannelSettings);
                }
                else if (pcrExperimentProject.SystemType == PcrSystemType.Allele)
                {
                    mProjectEditor = new FormAlleleProjectEditor(mApplication, pcrExperimentProject, isNewProject, isAllowToChangeChannelSettings);
                }
                else if (pcrExperimentProject.SystemType == PcrSystemType.GeneScan)
                {
                    mProjectEditor = new FormGeneScanProjectEditor(mApplication, pcrExperimentProject, isNewProject, isAllowToChangeChannelSettings);
                }
                if (mProjectEditor.ShowDialog() == DialogResult.OK)
                {
                    result = mProjectEditor.PcrExperimentProject.FileName;
                }
                mProjectEditor = null;
            }
            else
            {
                mProjectEditor.OpenPcrProject(pcrExperimentProject);
                result = mProjectEditor.PcrExperimentProject.FileName;
            }
            mApplication.SetCursor(Cursors.Default);
            return result;
        }

        public void SaveExperimentProject(IPcrExperimentProject pcrExperimentProject)
        {
            pcrExperimentProject.Update();
            if (pcrExperimentProject.Cells != null)
            {
                pcrExperimentProject.Cells.Clear();
            }
            if (CheckAvailableProgramSegment(pcrExperimentProject.PcrProgram))
            {
                pcrExperimentProject.Name = Path.GetFileNameWithoutExtension(pcrExperimentProject.FileName);
                mMiscService.SerializeBinaryFile(pcrExperimentProject.FileName, FileMode.Create, pcrExperimentProject);
            }
            else
            {
                MessageBox.Show(mResourceManager.GetString("ThermalProfileEmpty"), mResourceManager.GetString("ErrorString"));
            }
        }

        public bool CheckAvailableProgramSegment(IPcrProgram pcrProgram)
        {
            if (pcrProgram.AvailableAmplificationSegmentCount <= 0 && pcrProgram.MeltingStepCount == 0)
            {
                return false;
            }
            return true;
        }

        public string SaveAsExperimentProject(IPcrExperimentProject pcrExperimentProject, string filePathName)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            string fileName = Path.GetFileName(filePathName);
            string directoryName = Path.GetDirectoryName(filePathName);
            if (string.IsNullOrEmpty(fileName))
            {
                if (!Directory.Exists(directoryName))
                {
                    saveFileDialog.InitialDirectory = mApplication.GetAssemblyPath() + mConfigurationService.ProjectFileDefaultFolder;
                }
                else
                {
                    saveFileDialog.InitialDirectory = directoryName;
                }
            }
            else
            {
                if (!Directory.Exists(directoryName))
                {
                    saveFileDialog.InitialDirectory = mApplication.GetAssemblyPath() + mConfigurationService.ProjectFileDefaultFolder + "\\";
                }
                else
                {
                    saveFileDialog.InitialDirectory = directoryName;
                }
                saveFileDialog.FileName = fileName;
            }
            saveFileDialog.Filter = "Project file(*.prj)|*.prj";
            saveFileDialog.DefaultExt = ".prj";
            saveFileDialog.Title = mResourceManager.GetString("SaveProjectFile");
            if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return null;
            }
            if (!string.IsNullOrEmpty(saveFileDialog.FileName))
            {
                pcrExperimentProject.FileName = saveFileDialog.FileName;
                pcrExperimentProject.PcrProgram.PcrExperimentProject = pcrExperimentProject;
                SaveExperimentProject(pcrExperimentProject);
            }
            return saveFileDialog.FileName;
        }

        public IPcrExperimentProject LoadExperimentProjectFile(string projectFileName)
        {
            IPcrExperimentProject pcrExperimentProject = mMiscService.DeSerializeBinaryFile(projectFileName) as IPcrExperimentProject;
            if (pcrExperimentProject.Cells != null)
            {
                pcrExperimentProject.Cells.Clear();
            }
            IProjectItem[] projectItems = pcrExperimentProject.ProjectItems;
            foreach (IProjectItem projectItem in projectItems)
            {
                if (projectItem != null)
                {
                    projectItem.ChannelConfiguration.IsAvailable = projectItem.ChannelConfiguration.IsSelected;
                }
            }
            if (pcrExperimentProject.FileName.CompareTo(projectFileName) != 0)
            {
                pcrExperimentProject.FileName = projectFileName;
                pcrExperimentProject.Name = Path.GetFileNameWithoutExtension(pcrExperimentProject.FileName);
                mMiscService.SerializeBinaryFile(projectFileName, FileMode.Create, pcrExperimentProject);
                pcrExperimentProject = mMiscService.DeSerializeBinaryFile(projectFileName) as IPcrExperimentProject;
            }
            pcrExperimentProject.SetApplication(mApplication);
            return pcrExperimentProject;
        }

        public UltraTabControl CreateItemGridTabControl()
        {
            UltraTabControl ultraTabControl = new UltraTabControl();
            ((ISupportInitialize)ultraTabControl).BeginInit();
            ultraTabControl.Dock = DockStyle.Fill;
            ultraTabControl.Size = new Size(500, 200);
            ultraTabControl.Name = "Project Type Tab Control";
            ultraTabControl.ViewStyle = Infragistics.Win.UltraWinTabControl.ViewStyle.VisualStudio2005;
            ultraTabControl.TabLayoutStyle = TabLayoutStyle.SingleRowAutoSize;
            ultraTabControl.TabOrientation = TabOrientation.Default;
            ultraTabControl.ScrollButtons = TabScrollButtons.Always;
            ultraTabControl.AllowTabClosing = false;
            ultraTabControl.AllowTabMoving = false;
            ultraTabControl.Style = UltraTabControlStyle.Wizard;
            ((ISupportInitialize)ultraTabControl).EndInit();
            DataTable pcrSystemTypeTable = mConfigurationService.PcrSystemTypeTable;
            foreach (DataRow row in pcrSystemTypeTable.Rows)
            {
                PcrSystemType pcrSystemType = (PcrSystemType)row[0];
                UltraTab ultraTab = new UltraTab();
                UltraTabPageControl ultraTabPageControl2 = (ultraTab.TabPage = new UltraTabPageControl());
                ultraTab.Text = row[0].ToString();
                ultraTab.Key = row[0].ToString();
                ultraTabPageControl2.Name = row[0].ToString();
                ultraTabPageControl2.Tag = pcrSystemType;
                ultraTabControl.Controls.Add(ultraTabPageControl2);
                ultraTabControl.Tabs.Add(ultraTab);
                if (pcrSystemType.Equals(PcrSystemType.AbsoluteAnalysis))
                {
                    ultraTabPageControl2.Controls.Add((Control)(object)CreateAbsoluteItemGrid(null, null));
                }
                else if (pcrSystemType.Equals(PcrSystemType.GeneScan))
                {
                    ultraTabPageControl2.Controls.Add((Control)(object)CreateGeneScanItemGrid(null, null));
                }
                else if (pcrSystemType.Equals(PcrSystemType.Allele))
                {
                    ultraTabPageControl2.Controls.Add((Control)(object)CreateAlleleItemGrid(null, null));
                }
            }
            ultraTabControl.Tabs[0].Selected = true;
            ultraTabControl.Tabs[0].Active = true;
            return ultraTabControl;
        }

        public Grid CreateAbsoluteItemGrid(IPcrExperimentProject experimentProject, Grid mItemGrid)
        {
            //IL_0053: Unknown result type (might be due to invalid IL or missing references)
            //IL_005d: Expected O, but got Unknown
            //IL_0065: Unknown result type (might be due to invalid IL or missing references)
            //IL_006f: Expected O, but got Unknown
            //IL_0077: Unknown result type (might be due to invalid IL or missing references)
            //IL_0081: Expected O, but got Unknown
            //IL_0089: Unknown result type (might be due to invalid IL or missing references)
            //IL_0093: Expected O, but got Unknown
            //IL_0020: Unknown result type (might be due to invalid IL or missing references)
            //IL_0027: Expected O, but got Unknown
            //IL_0338: Unknown result type (might be due to invalid IL or missing references)
            //IL_0342: Expected O, but got Unknown
            //IL_034a: Unknown result type (might be due to invalid IL or missing references)
            //IL_0354: Expected O, but got Unknown
            //IL_035c: Unknown result type (might be due to invalid IL or missing references)
            //IL_0366: Expected O, but got Unknown
            //IL_036e: Unknown result type (might be due to invalid IL or missing references)
            //IL_0378: Expected O, but got Unknown
            IChannelConfiguration[] array = ((experimentProject == null) ? mConfigurationService.ChannelConfigurations() : experimentProject.ChannelConfigurations);
            if (mItemGrid == null)
            {
                mItemGrid = new Grid();
                ((Control)(object)mItemGrid).Location = new Point(0, 0);
                ((Control)(object)mItemGrid).Size = new Size(345, 170);
            }
            else
            {
                mItemGrid.CellChange -= new CellChangeEventHandler(mItemGrid_CellChange);
                mItemGrid.LeaveCell -= new LeaveCellEventHandler(mItemGrid_LeaveCell);
                mItemGrid.KeyDown -= new KeyDownEventHandler(mItemGrid_KeyDown);
                mItemGrid.RowColChange -= new RowColChangeEventHandler(mItemGrid_RowColChange);
            }
            mItemGrid.AutoRedraw = false;
            mItemGrid.DefaultFont = new Font("SimSun", 9f);
            ((Control)(object)mItemGrid).Dock = DockStyle.Fill;
            mItemGrid.Font = new Font("SimSun", 9f);
            ((Control)(object)mItemGrid).Name = "ItemGrid";
            mItemGrid.Cols = array.Length + 1;
            mItemGrid.Rows = 4;
            mItemGrid.ExtendLastCol = false;
            mItemGrid.ShowResizeTip = false;
            mItemGrid.AllowUserResizing = (ResizeEnum)0;
            mItemGrid.DisplayFocusRect = false;
            mItemGrid.DisplayRowNumber = false;
            mItemGrid.Cell(0, 0).Text = mResourceManager.GetString("ChannelString");
            mItemGrid.Cell(1, 0).Text = mResourceManager.GetString("DyeString");
            mItemGrid.Cell(2, 0).Text = mResourceManager.GetString("UseChannelString");
            mItemGrid.Cell(3, 0).Text = mResourceManager.GetString("TargetNameString");
            mItemGrid.Column(0).Width = 80;
            for (int i = 1; i < mItemGrid.Cols; i++)
            {
                mItemGrid.Column(i).Width = 80;
                mItemGrid.Cell(1, i).Locked = true;
                mItemGrid.Cell(2, i).CellType = (CellTypeEnum)2;
                mItemGrid.Column(i).Alignment = (AlignmentEnum)10;
                mItemGrid.Cell(2, i).Text = "False";
                mItemGrid.Cell(3, i).Text = string.Empty;
                if (i - 1 < array.Length)
                {
                    mItemGrid.Cell(0, i).Text = i.ToString();
                    mItemGrid.Cell(1, i).Text = array[i - 1].Content;
                    if (!array[i - 1].IsAvailable)
                    {
                        mItemGrid.Cell(1, i).BackColor = Color.WhiteSmoke;
                        mItemGrid.Cell(2, i).BackColor = Color.WhiteSmoke;
                        mItemGrid.Cell(3, i).BackColor = Color.WhiteSmoke;
                        mItemGrid.Cell(3, i).Locked = true;
                        mItemGrid.Cell(2, i).Locked = true;
                    }
                    else
                    {
                        mItemGrid.Cell(1, i).BackColor = Color.White;
                        mItemGrid.Cell(2, i).BackColor = Color.White;
                        mItemGrid.Cell(3, i).BackColor = Color.WhiteSmoke;
                        mItemGrid.Cell(3, i).Locked = true;
                        mItemGrid.Cell(2, i).Locked = false;
                    }
                }
                mItemGrid.Column(i).AutoFit();
            }
            mItemGrid.AutoRedraw = true;
            mItemGrid.Refresh();
            for (int j = 1; j < mItemGrid.Cols; j++)
            {
                if (mItemGrid.Column(j).Width < 75)
                {
                    mItemGrid.Column(j).Width = 75;
                }
            }
            mItemGrid.CellChange += new CellChangeEventHandler(mItemGrid_CellChange);
            mItemGrid.LeaveCell += new LeaveCellEventHandler(mItemGrid_LeaveCell);
            mItemGrid.KeyDown += new KeyDownEventHandler(mItemGrid_KeyDown);
            mItemGrid.RowColChange += new RowColChangeEventHandler(mItemGrid_RowColChange);
            return mItemGrid;
        }

        public Grid CreateAlleleItemGrid(IPcrExperimentProject experimentProject, Grid mItemGrid)
        {
            //IL_0051: Unknown result type (might be due to invalid IL or missing references)
            //IL_005b: Expected O, but got Unknown
            //IL_0063: Unknown result type (might be due to invalid IL or missing references)
            //IL_006d: Expected O, but got Unknown
            //IL_0075: Unknown result type (might be due to invalid IL or missing references)
            //IL_007f: Expected O, but got Unknown
            //IL_0087: Unknown result type (might be due to invalid IL or missing references)
            //IL_0091: Expected O, but got Unknown
            //IL_0099: Unknown result type (might be due to invalid IL or missing references)
            //IL_00a3: Expected O, but got Unknown
            //IL_0243: Unknown result type (might be due to invalid IL or missing references)
            //IL_024d: Expected O, but got Unknown
            //IL_0020: Unknown result type (might be due to invalid IL or missing references)
            //IL_0027: Expected O, but got Unknown
            IChannelConfiguration[] array = ((experimentProject == null) ? mConfigurationService.ChannelConfigurations() : experimentProject.ChannelConfigurations);
            if (mItemGrid == null)
            {
                mItemGrid = new Grid();
                ((Control)(object)mItemGrid).Location = new Point(0, 0);
                ((Control)(object)mItemGrid).Size = new Size(345, 170);
            }
            mItemGrid.CellChange -= new CellChangeEventHandler(mGeneScanItemGrid_CellChange);
            mItemGrid.CellChange -= new CellChangeEventHandler(mItemGrid_CellChange);
            mItemGrid.LeaveCell -= new LeaveCellEventHandler(mItemGrid_LeaveCell);
            mItemGrid.KeyDown -= new KeyDownEventHandler(mItemGrid_KeyDown);
            mItemGrid.RowColChange -= new RowColChangeEventHandler(mItemGrid_RowColChange);
            mItemGrid.DefaultFont = new Font("SimSun", 9f);
            ((Control)(object)mItemGrid).Dock = DockStyle.Fill;
            mItemGrid.Font = new Font("SimSun", 9f);
            ((Control)(object)mItemGrid).Name = "ItemGrid";
            mItemGrid.AutoRedraw = false;
            mItemGrid.Cols = 4;
            mItemGrid.Rows = 3;
            mItemGrid.ExtendLastCol = false;
            mItemGrid.ShowResizeTip = false;
            mItemGrid.AllowUserResizing = (ResizeEnum)0;
            mItemGrid.DisplayFocusRect = false;
            mItemGrid.DisplayRowNumber = false;
            mItemGrid.Cell(0, 0).Text = "";
            mItemGrid.Cell(1, 0).Text = "Allele1";
            mItemGrid.Cell(2, 0).Text = "Allele2";
            mItemGrid.Cell(0, 1).Text = mResourceManager.GetString("TargetNameString");
            mItemGrid.Cell(0, 2).Text = mResourceManager.GetString("ChannelString");
            mItemGrid.Cell(0, 3).Text = mResourceManager.GetString("DyeString");
            mItemGrid.Column(0).Width = 80;
            mItemGrid.Column(1).Width = 80;
            mItemGrid.Column(2).Width = 80;
            mItemGrid.Column(3).Width = 80;
            mItemGrid.Column(0).Alignment = (AlignmentEnum)10;
            mItemGrid.Column(1).Alignment = (AlignmentEnum)10;
            mItemGrid.Column(2).Alignment = (AlignmentEnum)10;
            mItemGrid.Column(3).Alignment = (AlignmentEnum)10;
            mItemGrid.Column(2).CellType = (CellTypeEnum)1;
            mItemGrid.ComboBox(2).Locked = true;
            mItemGrid.Column(3).Locked = true;
            mItemGrid.CellChanging += new CellChangingEventHandler(mAlleleItemGrid_CellChanging);
            ((Control)(object)mItemGrid).Tag = array;
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].IsAvailable)
                {
                    mItemGrid.ComboBox(2).Items.Add(array[i].Position + 1);
                }
            }
            mItemGrid.ComboBox(2).Items.Add(" ");
            mItemGrid.AutoRedraw = true;
            mItemGrid.Refresh();
            return mItemGrid;
        }

        public Grid CreateGeneScanItemGrid(IPcrExperimentProject experimentProject, Grid mItemGrid)
        {
            //IL_0011: Unknown result type (might be due to invalid IL or missing references)
            //IL_001b: Expected O, but got Unknown
            //IL_0023: Unknown result type (might be due to invalid IL or missing references)
            //IL_002d: Expected O, but got Unknown
            Grid val = CreateAbsoluteItemGrid(experimentProject, mItemGrid);
            val.CellChange -= new CellChangeEventHandler(mItemGrid_CellChange);
            val.CellChange += new CellChangeEventHandler(mGeneScanItemGrid_CellChange);
            return val;
        }

        public void RefreshItemGridContent(Grid mItemGrid, IPcrExperimentProject experimentProject, bool isLockSelection)
        {
            if (experimentProject.SystemType == PcrSystemType.AbsoluteAnalysis || experimentProject.SystemType == PcrSystemType.GeneScan)
            {
                RefreshAbsoluteItemGridContent(mItemGrid, experimentProject, isLockSelection);
            }
            else
            {
                RefreshAlleleItemGridContent(mItemGrid, experimentProject, isLockSelection);
            }
        }

        public void RefreshAbsoluteItemGridContent(Grid mItemGrid, IPcrExperimentProject experimentProject, bool isLockSelection)
        {
            //IL_0010: Unknown result type (might be due to invalid IL or missing references)
            //IL_001a: Expected O, but got Unknown
            //IL_02bd: Unknown result type (might be due to invalid IL or missing references)
            //IL_02c7: Expected O, but got Unknown
            if (mItemGrid == null || experimentProject == null)
            {
                return;
            }
            mItemGrid.LeaveCell -= new LeaveCellEventHandler(mItemGrid_LeaveCell);
            mItemGrid.AutoRedraw = false;
            mItemGrid.Rows = 3;
            mItemGrid.Rows = experimentProject.TubeCount + 3;
            int num = 0;
            IProjectItem[] projectItems = experimentProject.ProjectItems;
            foreach (IProjectItem projectItem in projectItems)
            {
                num++;
                if (projectItem != null)
                {
                    num = projectItem.ChannelConfiguration.Position + 1;
                    if (projectItem.ChannelConfiguration.IsSelected && !string.IsNullOrEmpty(projectItem.Name))
                    {
                        string[] array = projectItem.Name.Split(new string[1] { "," }, StringSplitOptions.None);
                        if (array == null)
                        {
                            continue;
                        }
                        mItemGrid.Cell(2, num).Text = "1";
                        mItemGrid.Cell(2, num).Locked = isLockSelection;
                        mItemGrid.Cell(2, num).BackColor = Color.White;
                        for (int j = 3; j < mItemGrid.Rows; j++)
                        {
                            if (j - 3 < array.Length)
                            {
                                mItemGrid.Cell(j, num).Text = array[j - 3];
                            }
                            else
                            {
                                mItemGrid.Cell(j, num).Text = string.Empty;
                            }
                            mItemGrid.Cell(j, num).Locked = isLockSelection;
                            mItemGrid.Cell(j, num).BackColor = Color.White;
                            mItemGrid.Row(j).Visible = true;
                        }
                    }
                    else
                    {
                        for (int k = 3; k < mItemGrid.Rows; k++)
                        {
                            mItemGrid.Cell(k, num).Text = string.Empty;
                            mItemGrid.Cell(k, num).Locked = true;
                            mItemGrid.Cell(k, num).BackColor = Color.WhiteSmoke;
                        }
                        mItemGrid.Cell(2, num).Text = "0";
                        mItemGrid.Cell(2, num).Locked = isLockSelection;
                        mItemGrid.Cell(2, num).BackColor = (isLockSelection ? Color.WhiteSmoke : Color.White);
                    }
                }
                else
                {
                    for (int l = 3; l < mItemGrid.Rows; l++)
                    {
                        mItemGrid.Cell(l, num).Text = string.Empty;
                        mItemGrid.Cell(l, num).Locked = true;
                        mItemGrid.Cell(l, num).BackColor = Color.WhiteSmoke;
                    }
                    mItemGrid.Cell(2, num).Text = "0";
                    mItemGrid.Cell(2, num).Locked = isLockSelection || !experimentProject.ChannelConfigurations[num - 1].IsAvailable;
                    mItemGrid.Cell(2, num).BackColor = (mItemGrid.Cell(2, num).Locked ? Color.WhiteSmoke : Color.White);
                }
            }
            RefreshAbsoluteGridTargetNameDisplay(mItemGrid);
            mItemGrid.AutoRedraw = true;
            mItemGrid.Refresh();
            mItemGrid.Cell(1, 1).SetFocus();
            mItemGrid.LeaveCell += new LeaveCellEventHandler(mItemGrid_LeaveCell);
        }

        public void RefreshAlleleItemGridContent(Grid mItemGrid, IPcrExperimentProject experimentProject, bool isLockSelection)
        {
            //IL_0008: Unknown result type (might be due to invalid IL or missing references)
            //IL_0012: Expected O, but got Unknown
            //IL_0128: Unknown result type (might be due to invalid IL or missing references)
            //IL_0132: Expected O, but got Unknown
            mItemGrid.CellChanging -= new CellChangingEventHandler(mAlleleItemGrid_CellChanging);
            mItemGrid.AutoRedraw = false;
            int num = 0;
            IProjectItem[] projectItems = experimentProject.ProjectItems;
            foreach (IProjectItem projectItem in projectItems)
            {
                if (projectItem == null)
                {
                    continue;
                }
                num++;
                int num2 = projectItem.ChannelConfiguration.Position + 1;
                if (projectItem.ChannelConfiguration.IsSelected && !string.IsNullOrEmpty(projectItem.Name))
                {
                    string[] array = projectItem.Name.Split(new string[1] { "," }, StringSplitOptions.None);
                    if (array != null && array.Length > 0)
                    {
                        mItemGrid.Cell(num, 1).Text = array[0];
                        mItemGrid.Cell(num, 2).Text = num2.ToString();
                        mItemGrid.Cell(num, 3).Text = projectItem.Dye;
                    }
                }
            }
            for (int j = 0; j < mItemGrid.Cols; j++)
            {
                if (!mItemGrid.Column(j).Locked)
                {
                    mItemGrid.Column(j).Locked = isLockSelection;
                }
            }
            mItemGrid.AutoRedraw = true;
            mItemGrid.Refresh();
            mItemGrid.Cell(1, 1).SetFocus();
            mItemGrid.CellChanging += new CellChangingEventHandler(mAlleleItemGrid_CellChanging);
        }

        public void RefreshAbsoluteGridTargetNameDisplay(Grid mItemGrid)
        {
            if (mItemGrid.Rows == 4)
            {
                mItemGrid.Cell(3, 0).Text = mResourceManager.GetString("TargetNameString");
                for (int i = 1; i < mItemGrid.Cols; i++)
                {
                    if (mItemGrid.Cell(3, i).Text.Equals("N/A"))
                    {
                        mItemGrid.Cell(3, i).Text = string.Empty;
                    }
                }
            }
            else
            {
                for (int j = 3; j < mItemGrid.Rows; j++)
                {
                    mItemGrid.Cell(j, 0).Text = "TUBE" + (j - 2);
                    if (j > 3)
                    {
                        for (int k = 1; k < mItemGrid.Cols; k++)
                        {
                            mItemGrid.Cell(j, k).BackColor = mItemGrid.Cell(3, k).BackColor;
                            mItemGrid.Cell(j, k).Locked = mItemGrid.Cell(3, k).Locked;
                        }
                    }
                }
            }
            mItemGrid.Column(0).AutoFit();
        }

        public IPcrExperimentProject CreateNewEmptyProject()
        {
            return CreateNewEmptyProject(PcrSystemType.AbsoluteAnalysis);
        }

        public IPcrExperimentProject CreateNewEmptyProject(PcrSystemType systemType)
        {
            switch (systemType)
            {
                case PcrSystemType.Allele:
                    return new AllelePcrExperimentProject(mApplication);
                case PcrSystemType.GeneType:
                    return new GeneTypePcrExperimentProject(mApplication);
                case PcrSystemType.GeneScan:
                    return new GeneScanPcrExperimentProject(mApplication);
                case PcrSystemType.RelativeQuantification:
                    return new RelativeQuantificationPcrExperimentProject(mApplication);
                default:
                    return new AbsolutePcrExperimentProject(mApplication);
            }
        }

        private string LoadNewExperimentProjectEditor(PcrSystemType systemType)
        {
            FormProjectOption formProjectOption = new FormProjectOption(mApplication, systemType);
            if (formProjectOption.ShowDialog() == DialogResult.OK)
            {
                return LoadExperimentProjectEditor(formProjectOption.ExperimentProject, true, false, false);
            }
            return string.Empty;
        }

        public IPcrExperimentProject CreateNewProjectFromEditor(PcrSystemType systemType)
        {
            string text = LoadNewExperimentProjectEditor(systemType);
            if (!string.IsNullOrEmpty(text))
            {
                return LoadExperimentProjectFile(text);
            }
            return null;
        }

        public void ClearProgramCurve(UltraChart chartProgram, UltraScrollBar scrollBar)
        {
            InitializeProgramCurve(chartProgram);
            chartProgram.Series.Clear();
            chartProgram.Annotations.Annotations.Clear();
            scrollBar.Visible = false;
        }

        public void DrawExperimentProgramCurve(UltraChart chartProgram, IPcrProgram pcrProgram, bool chartInitialization, UltraScrollBar scrollBar, bool isShowTitle, bool isShowRunningTime)
        {
            if (pcrProgram == null)
            {
                return;
            }
            int num = 0;
            if (chartInitialization)
            {
                InitializeProgramCurve(chartProgram);
            }
            chartProgram.Axis.X.RangeMax = Convert.ToInt32((double)chartProgram.Width / mPcrProgramConfiguration.StepWidthInGraph);
            if (chartProgram.Series.Count > 0)
            {
                chartProgram.Series.Clear();
            }
            if (chartProgram.Annotations.Annotations.Count > 0)
            {
                chartProgram.Annotations.Annotations.Clear();
            }
            InitializeAmplificationSeries(chartProgram);
            if (pcrProgram != null)
            {
                for (int i = 0; i < pcrProgram.AmplificationSegmentCount; i++)
                {
                    IAmplificationSegment amplificationSegment = pcrProgram.GetAmplificationSegment(i);
                    if (amplificationSegment.IsAvailable && amplificationSegment.StepTable.Rows.Count > 0)
                    {
                        num += amplificationSegment.StepTable.Rows.Count;
                        DrawAmplificationStepCurve(chartProgram, amplificationSegment);
                    }
                }
                IMeltingSegment meltingSegment = pcrProgram.GetMeltingSegment(0);
                if (meltingSegment.IsAvailable)
                {
                    num += 2;
                    DrawMeltingStepCurve(chartProgram, meltingSegment, pcrProgram.PcrExperimentProject);
                }
                IMeltingSegment hRMSegment = pcrProgram.GetHRMSegment(0);
                if (hRMSegment.IsAvailable)
                {
                    num += 2;
                    DrawMeltingStepCurve(chartProgram, hRMSegment, pcrProgram.PcrExperimentProject);
                }
            }
            int num2 = Convert.ToInt32((double)num - chartProgram.Axis.X.RangeMax);
            if (num2 > 0)
            {
                scrollBar.Visible = true;
                scrollBar.Initialize(0, num2, 1, 2);
                scrollBar.Value = 0;
            }
            else
            {
                scrollBar.Visible = false;
            }
            if (isShowTitle && pcrProgram != null)
            {
                chartProgram.TitleTop.Visible = true;
                chartProgram.TitleTop.Text = pcrProgram.PcrExperimentProject.FileName;
                chartProgram.TitleTop.Extent = 40;
                chartProgram.TitleTop.HorizontalAlign = StringAlignment.Center;
                chartProgram.TitleTop.VerticalAlign = StringAlignment.Near;
            }
            else
            {
                chartProgram.TitleTop.Visible = true;
                chartProgram.TitleTop.Extent = 20;
                chartProgram.TitleTop.Text = "      ";
            }
            if (isShowRunningTime && pcrProgram != null)
            {
                BoxAnnotation boxAnnotation = new BoxAnnotation();
                boxAnnotation.Height = -1;
                boxAnnotation.Width = -1;
                boxAnnotation.Location.Type = LocationType.DataValues;
                double num3 = mMiscService.ConvertActualIntervalFromPixel(chartProgram.Height, mPcrProgramConfiguration.GraphVerticalRatio, 5.0);
                boxAnnotation.Location.ValueX = chartProgram.Axis.X.RangeMax - 1.0;
                boxAnnotation.Location.ValueY = chartProgram.Axis.Y.RangeMax + num3;
                boxAnnotation.Text = mResourceManager.GetString("ExperimentTime") + " " + pcrProgram.GetExperimentTotalTime(false);
                boxAnnotation.Border.Color = Color.Black;
                boxAnnotation.Border.Thickness = 0;
                boxAnnotation.TextStyle.Font = mPcrProgramConfiguration.StepAnnonationFont;
                boxAnnotation.TextStyle.HorizontalAlign = StringAlignment.Center;
                boxAnnotation.TextStyle.VerticalAlign = StringAlignment.Center;
                chartProgram.Annotations.Add(boxAnnotation);
            }
        }

        public void RefreshChartScrollBar(UltraScrollBar scrollBar, UltraChart chartProgram, IPcrProgram pcrProgram)
        {
        }

        private void InitializeMenu()
        {
            IMenuService menuService = (IMenuService)mApplication.GetService("MenuService");
            if (menuService != null)
            {
                ToolStripMenuItem menuItem = menuService.GetMenuItem("menuProject");
                ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
                toolStripMenuItem.Name = "ProjectManager";
                toolStripMenuItem.Text = mResourceManager.GetString("MenuProjectManager");
                toolStripMenuItem.ShortcutKeys = Keys.M | Keys.Control;
                toolStripMenuItem.Click += menuProjectManager_Click;
                menuService.InsertMenuItem(0, menuItem, toolStripMenuItem);
                ToolStripMenuItem toolStripMenuItem2 = new ToolStripMenuItem();
                toolStripMenuItem2.Name = "CreateProject";
                toolStripMenuItem2.Text = mResourceManager.GetString("MenuCreateProject");
                toolStripMenuItem2.ShortcutKeys = Keys.R | Keys.Control;
                toolStripMenuItem2.Click += menuCreateProject_Click;
                toolStripMenuItem2.Enabled = mConfigurationService.ProjectAuthorization.Equals(ProjectAuthorizationEnum.System);
                menuService.InsertMenuItem(1, menuItem, toolStripMenuItem2);
                ToolStripMenuItem toolStripMenuItem3 = new ToolStripMenuItem();
                toolStripMenuItem3.Name = "EditProject";
                toolStripMenuItem3.Text = mResourceManager.GetString("MenuEditProject");
                toolStripMenuItem3.ShortcutKeys = Keys.E | Keys.Control;
                toolStripMenuItem3.Click += menuEditProject_Click;
                toolStripMenuItem3.Enabled = mConfigurationService.ProjectAuthorization.Equals(ProjectAuthorizationEnum.System);
                menuService.InsertMenuItem(2, menuItem, toolStripMenuItem3);
            }
        }

        private void InitializeAmplificationSeries(UltraChart chartProgram)
        {
            XYSeries xYSeries = new XYSeries();
            xYSeries.PEs.Add(new PaintElement(mPcrProgramConfiguration.TemperatureCurveColor));
            xYSeries.Key = "AmplificationPoints";
            XYDataPoint point = new XYDataPoint(-1.0, 50.0, "", false);
            xYSeries.Points.Add(point);
            chartProgram.Series.Add(xYSeries);
        }

        private void DrawAmplificationStepCurve(UltraChart chartProgram, IAmplificationSegment amplificationSegment)
        {
            double num = 0.0;
            XYDataPointCollection points = (chartProgram.Series[0] as XYSeries).Points;
            double result = 0.0;
            double num2 = mMiscService.ConvertActualIntervalFromPixel(chartProgram.Height, mPcrProgramConfiguration.GraphVerticalRatio, mPcrProgramConfiguration.StepAnnonationVerticalInterval);
            double num3;
            XYDataPoint point;
            string label;
            if (amplificationSegment.Index == 1)
            {
                points.Clear();
                label = "1";
                num3 = 0.0;
                if (!double.TryParse(amplificationSegment.StepTable.Rows[0]["Temperature"].ToString(), out result))
                {
                    result = 0.0;
                }
                point = new XYDataPoint(num3, result, label, false);
                points.Add(point);
            }
            else
            {
                num3 = points[points.Count - 1].ValueX;
            }
            double valueX;
            XYDataPoint xYDataPoint;
            for (int i = 0; i < amplificationSegment.StepTable.Rows.Count; i++)
            {
                DataRow dataRow = amplificationSegment.StepTable.Rows[i];
                if (!double.TryParse(dataRow["Temperature"].ToString(), out result))
                {
                    result = 0.0;
                }
                double num4 = points[points.Count - 1].ValueX + mPcrProgramConfiguration.StepSlopePercent;
                label = "Slop" + (points.Count + 1);
                point = new XYDataPoint(num4, result, label, false);
                points.Add(point);
                label = (points.Count + 1).ToString();
                xYDataPoint = new XYDataPoint(num4 + 1.0 - mPcrProgramConfiguration.StepSlopePercent, result, label, false);
                points.Add(xYDataPoint);
                num = xYDataPoint.ValueX;
                valueX = num4 + (num - num4) / 2.0;
                BoxAnnotation boxAnnotation = new BoxAnnotation();
                boxAnnotation.Height = -1;
                boxAnnotation.Width = -1;
                boxAnnotation.Location.Type = LocationType.DataValues;
                boxAnnotation.Location.ValueX = valueX;
                boxAnnotation.Location.ValueY = xYDataPoint.ValueY + num2;
                boxAnnotation.Text = result.ToString("0.0") + "℃";
                boxAnnotation.Border.Color = Color.Black;
                boxAnnotation.Border.Thickness = 0;
                boxAnnotation.TextStyle.Font = mPcrProgramConfiguration.StepAnnonationFont;
                boxAnnotation.TextStyle.HorizontalAlign = StringAlignment.Center;
                boxAnnotation.TextStyle.VerticalAlign = StringAlignment.Center;
                chartProgram.Annotations.Add(boxAnnotation);
                BoxAnnotation boxAnnotation2 = new BoxAnnotation();
                boxAnnotation2.Height = -1;
                boxAnnotation2.Width = -1;
                boxAnnotation2.Location.Type = LocationType.DataValues;
                boxAnnotation2.Location.ValueX = valueX;
                boxAnnotation2.Location.ValueY = xYDataPoint.ValueY - num2;
                boxAnnotation2.Text = dataRow["HoldTime"].ToString();
                boxAnnotation2.Border.Color = Color.Black;
                boxAnnotation2.Border.Thickness = 0;
                boxAnnotation2.TextStyle.Font = mPcrProgramConfiguration.StepAnnonationFont;
                boxAnnotation2.TextStyle.HorizontalAlign = StringAlignment.Center;
                boxAnnotation2.TextStyle.VerticalAlign = StringAlignment.Center;
                chartProgram.Annotations.Add(boxAnnotation2);
                BoxAnnotation boxAnnotation3 = new BoxAnnotation();
                int num5 = 1;
                boxAnnotation3.Height = -1;
                boxAnnotation3.Width = -1;
                boxAnnotation3.Location.Type = LocationType.DataValues;
                boxAnnotation3.Location.ValueX = valueX;
                boxAnnotation3.Text = string.Empty;
                if (Convert.ToBoolean(dataRow["Fluorescence"]))
                {
                    boxAnnotation3.Text = mResourceManager.GetString("FluorescenceString") + " \n";
                    num5++;
                }
                if (Convert.ToBoolean(dataRow["Advanced"]))
                {
                    string text = (Convert.ToBoolean(dataRow["TemperatureVariation"]) ? "+" : "-");
                    double result2 = 0.0;
                    double.TryParse(dataRow["TemperatureValue"].ToString(), out result2);
                    if (result2 != 0.0)
                    {
                        object text2 = boxAnnotation3.Text;
                        boxAnnotation3.Text = string.Concat(text2, text, Math.Round(result2, 2), "℃\n");
                        num5++;
                    }
                    string text3 = (Convert.ToBoolean(dataRow["TimeVariation"]) ? "+" : "-");
                    string text4 = dataRow["TimeValue"].ToString();
                    if (text4 != "00:00" && text4 != "0")
                    {
                        boxAnnotation3.Text = boxAnnotation3.Text + text3 + text4 + "\n";
                        num5++;
                    }
                    double result3 = 0.0;
                    double.TryParse(dataRow["Rising/FallingRate"].ToString(), out result3);
                    if (result3 != 0.0)
                    {
                        boxAnnotation3.Text = boxAnnotation3.Text + result3 + "℃/s\n";
                        num5++;
                    }
                }
                boxAnnotation3.Location.ValueY = boxAnnotation2.Location.ValueY - (double)num5 * num2;
                boxAnnotation3.Border.Color = Color.Black;
                boxAnnotation3.Border.Thickness = 0;
                boxAnnotation3.TextStyle.Font = mPcrProgramConfiguration.StepAnnonationFont;
                boxAnnotation3.TextStyle.HorizontalAlign = StringAlignment.Center;
                boxAnnotation3.TextStyle.VerticalAlign = StringAlignment.Center;
                boxAnnotation3.Visible = boxAnnotation3.Text.Length > 0;
                chartProgram.Annotations.Add(boxAnnotation3);
            }
            BoxAnnotation boxAnnotation4 = new BoxAnnotation();
            valueX = num3 + (num - num3) / 2.0;
            double num6 = mMiscService.ConvertActualIntervalFromPixel(chartProgram.Height, mPcrProgramConfiguration.GraphVerticalRatio, mPcrProgramConfiguration.SegmentAnnonationVerticalInterval);
            boxAnnotation4.Height = -1;
            boxAnnotation4.Width = -1;
            boxAnnotation4.Location.Type = LocationType.DataValues;
            boxAnnotation4.Location.ValueX = valueX;
            boxAnnotation4.Location.ValueY = mPcrProgramConfiguration.MinTemperatureAxis + num6;
            boxAnnotation4.Text = amplificationSegment.Name + " × " + amplificationSegment.Cycle;
            boxAnnotation4.Border.Color = Color.Black;
            boxAnnotation4.Border.Thickness = 0;
            boxAnnotation4.TextStyle.Font = mPcrProgramConfiguration.SegmentAnnonationFont;
            boxAnnotation4.TextStyle.HorizontalAlign = StringAlignment.Center;
            boxAnnotation4.TextStyle.VerticalAlign = StringAlignment.Center;
            boxAnnotation4.Visible = true;
            chartProgram.Annotations.Add(boxAnnotation4);
            XYSeries xYSeries = new XYSeries();
            xYSeries.Key = "Segment" + amplificationSegment.Index;
            xYSeries.PEs.Add(new PaintElement(mPcrProgramConfiguration.SegmentLineColor));
            chartProgram.Series.Add(xYSeries);
            label = "Segment " + amplificationSegment.Index + "Start";
            point = new XYDataPoint(num, mPcrProgramConfiguration.MinTemperatureAxis, label, false);
            xYSeries.Points.Add(point);
            label = "Segment " + amplificationSegment.Index + "Stop";
            xYDataPoint = new XYDataPoint(num, mPcrProgramConfiguration.MaxTemperatureAxis, label, false);
            xYSeries.Points.Add(xYDataPoint);
        }

        private void DrawMeltingStepCurve(UltraChart chartProgram, IMeltingSegment meltingSegment, IPcrExperimentProject project)
        {
            double num = 0.0;
            XYDataPointCollection points = (chartProgram.Series[0] as XYSeries).Points;
            double num2 = mMiscService.ConvertActualIntervalFromPixel(chartProgram.Height, mPcrProgramConfiguration.GraphVerticalRatio, mPcrProgramConfiguration.StepAnnonationVerticalInterval);
            double num3;
            XYDataPoint point;
            string label;
            if (points.Count == 1)
            {
                label = "1";
                num3 = 0.0;
                point = new XYDataPoint(num3, meltingSegment.StartDegree, label, false);
                points.Add(point);
            }
            else
            {
                num3 = points[points.Count - 1].ValueX;
            }
            double[] array = new double[2] { meltingSegment.StartDegree, meltingSegment.StopDegree };
            double valueX;
            XYDataPoint xYDataPoint;
            for (int i = 0; i < array.Length; i++)
            {
                double valueY = array[i];
                double num4 = points[points.Count - 1].ValueX + mPcrProgramConfiguration.StepSlopePercent;
                label = "Slope" + (points.Count + 1);
                point = new XYDataPoint(num4, valueY, label, false);
                points.Add(point);
                label = (points.Count + 1).ToString();
                xYDataPoint = new XYDataPoint(num4 + 1.0, valueY, label, false);
                points.Add(xYDataPoint);
                num = xYDataPoint.ValueX;
                valueX = num4 + (num - num4) / 2.0;
                BoxAnnotation boxAnnotation = new BoxAnnotation();
                boxAnnotation.Height = -1;
                boxAnnotation.Width = -1;
                boxAnnotation.Location.Type = LocationType.DataValues;
                boxAnnotation.Location.ValueX = valueX;
                boxAnnotation.Location.ValueY = xYDataPoint.ValueY + num2;
                boxAnnotation.Text = valueY.ToString("0.0") + "℃";
                boxAnnotation.Border.Color = Color.Black;
                boxAnnotation.Border.Thickness = 0;
                boxAnnotation.TextStyle.Font = mPcrProgramConfiguration.StepAnnonationFont;
                boxAnnotation.TextStyle.HorizontalAlign = StringAlignment.Center;
                boxAnnotation.TextStyle.VerticalAlign = StringAlignment.Center;
                chartProgram.Annotations.Add(boxAnnotation);
            }
            BoxAnnotation boxAnnotation2 = new BoxAnnotation();
            valueX = num3 + (num - num3) / 2.0;
            double num5 = mMiscService.ConvertActualIntervalFromPixel(chartProgram.Height, mPcrProgramConfiguration.GraphVerticalRatio, mPcrProgramConfiguration.SegmentAnnonationVerticalInterval);
            boxAnnotation2.Height = -1;
            boxAnnotation2.Width = -1;
            boxAnnotation2.Location.Type = LocationType.DataValues;
            boxAnnotation2.Location.ValueX = valueX;
            boxAnnotation2.Location.ValueY = mPcrProgramConfiguration.MinTemperatureAxis + num5;
            string text = meltingSegment.ToString();
            if (text == null)
            {
                text = string.Empty;
            }
            if (text.Equals("HRM"))
            {
                boxAnnotation2.Text = "HRM";
                if (project != null)
                {
                    IGeneScanPcrExperimentProject geneScanPcrExperimentProject = project as IGeneScanPcrExperimentProject;
                    if (geneScanPcrExperimentProject != null)
                    {
                        boxAnnotation2.Text = boxAnnotation2.Text + " (" + geneScanPcrExperimentProject.HRMMode.ToString() + ")";
                        BoxAnnotation boxAnnotation3 = new BoxAnnotation();
                        boxAnnotation3.Height = -1;
                        boxAnnotation3.Width = -1;
                        boxAnnotation3.Location.Type = LocationType.DataValues;
                        boxAnnotation3.Location.ValueX = num3 + (num - num3) / 2.0;
                        num5 = mMiscService.ConvertActualIntervalFromPixel(chartProgram.Height, mPcrProgramConfiguration.GraphVerticalRatio, 10.0);
                        boxAnnotation3.Location.ValueY = boxAnnotation2.Location.ValueY + num5;
                        if (geneScanPcrExperimentProject.HRMMode == HRMModeEnum.Continue)
                        {
                            boxAnnotation3.Text = mResourceManager.GetString("RampString") + ":" + geneScanPcrExperimentProject.SettingRate;
                        }
                        else
                        {
                            boxAnnotation3.Text = mResourceManager.GetString("HRMIntervalString") + meltingSegment.StepInterval.ToString() + "\r\n" + mResourceManager.GetString("HRMHoldTimeString") + mMiscService.CovertTimeStringToSecond(meltingSegment.HoldTime);
                        }
                        boxAnnotation3.Border.Color = Color.Black;
                        boxAnnotation3.Border.Thickness = 0;
                        boxAnnotation3.TextStyle.Font = mPcrProgramConfiguration.StepAnnonationFont;
                        boxAnnotation3.TextStyle.HorizontalAlign = StringAlignment.Center;
                        boxAnnotation3.TextStyle.VerticalAlign = StringAlignment.Center;
                        chartProgram.Annotations.Add(boxAnnotation3);
                    }
                }
            }
            else
            {
                boxAnnotation2.Text = mResourceManager.GetString("MeltingString");
            }
            boxAnnotation2.Border.Color = Color.Black;
            boxAnnotation2.Border.Thickness = 0;
            boxAnnotation2.TextStyle.Font = mPcrProgramConfiguration.SegmentAnnonationFont;
            boxAnnotation2.TextStyle.HorizontalAlign = StringAlignment.Center;
            boxAnnotation2.TextStyle.VerticalAlign = StringAlignment.Center;
            boxAnnotation2.Visible = true;
            chartProgram.Annotations.Add(boxAnnotation2);
            XYSeries xYSeries = new XYSeries();
            xYSeries.Key = "Segment" + meltingSegment.Index;
            xYSeries.PEs.Add(new PaintElement(mPcrProgramConfiguration.SegmentLineColor));
            chartProgram.Series.Add(xYSeries);
            label = "Segment " + meltingSegment.Index + "Start";
            point = new XYDataPoint(num, mPcrProgramConfiguration.MinTemperatureAxis, label, false);
            xYSeries.Points.Add(point);
            label = "Segment " + meltingSegment.Index + "Stop";
            xYDataPoint = new XYDataPoint(num, mPcrProgramConfiguration.MaxTemperatureAxis, label, false);
            xYSeries.Points.Add(xYDataPoint);
        }

        public void GenerateProjectPropertyGrid(IPcrExperimentProject project, bool isCreate, bool isRefresh, bool isReadOnly, ref Grid grid)
        {
            if (grid == null)
            {
                return;
            }
            if (isCreate)
            {
                ((Control)(object)grid).Tag = project;
                grid.DefaultFont = new Font("SimSun", 9f);
                ((Control)(object)grid).Dock = DockStyle.Fill;
                grid.Font = new Font("SimSun", 9f);
                ((Control)(object)grid).Location = new Point(0, 0);
                ((Control)(object)grid).Name = "PropertyGrid";
                ((Control)(object)grid).Size = new Size(345, 170);
                grid.Cols = 4;
                grid.Rows = 1;
                grid.ExtendLastCol = false;
                grid.ShowResizeTip = false;
                grid.AllowUserResizing = (ResizeEnum)0;
                grid.DisplayFocusRect = false;
                grid.DisplayRowNumber = true;
                grid.Cell(0, 1).Text = mResourceManager.GetString("TargetNameString");
                grid.Cell(0, 2).Text = mResourceManager.GetString("QuantitativeThresholdString");
                grid.Cell(0, 3).Text = mResourceManager.GetString("QualitativeThresholdString");
                grid.Column(1).Width = 100;
                grid.Column(2).Width = 200;
                grid.Column(3).Width = 200;
                grid.Column(2).Mask = (MaskEnum)6;
                grid.Column(3).Mask = (MaskEnum)6;
                grid.Column(1).Locked = true;
                if (isReadOnly)
                {
                    grid.Column(2).Locked = true;
                    grid.Column(3).Locked = true;
                }
                for (int i = 1; i < grid.Cols; i++)
                {
                    grid.Column(i).Alignment = (AlignmentEnum)10;
                }
            }
            if (!isRefresh)
            {
                return;
            }
            List<IProjectProperty> projectPropertyList = project.ProjectPropertyList;
            grid.AutoRedraw = false;
            grid.Rows = projectPropertyList.Count + 1;
            for (int j = 1; j < grid.Rows; j++)
            {
                if (!string.IsNullOrEmpty(projectPropertyList[j - 1].ProjectName))
                {
                    grid.Cell(j, 1).Text = projectPropertyList[j - 1].ProjectName;
                    grid.Row(j).Visible = true;
                }
                else
                {
                    int num = j - 1;
                    if (num < project.ProjectItems.Length)
                    {
                        if (project.ProjectItems[num] == null)
                        {
                            grid.Row(j).Visible = false;
                        }
                        else if (project.ProjectItems[num].ChannelConfiguration.IsSelected)
                        {
                            grid.Cell(j, 1).Text = project.ProjectItems[num].Name;
                            projectPropertyList[j - 1].ProjectName = project.ProjectItems[num].Name;
                            grid.Row(j).Visible = true;
                        }
                        else
                        {
                            grid.Row(j).Visible = false;
                        }
                    }
                    else
                    {
                        grid.Row(j).Visible = false;
                    }
                }
                grid.Cell(j, 2).Text = (projectPropertyList[j - 1] as IAbsoluteProjectProperty).QuantitativeThreshold.ToString();
                grid.Cell(j, 3).Text = (projectPropertyList[j - 1] as IAbsoluteProjectProperty).QualitativeThreshold.ToString();
            }
            grid.AutoRedraw = true;
            grid.Refresh();
        }

        public bool GenerateCrossTalkGrid(IPcrExperimentProject experimentProject, UltraGrid crossTalkGrid, bool isToRefreshGridValue, bool isLocked)
        {
            DataTable dataTable = new DataTable();
            int channelCount = mConfigurationService.ChannelCount;
            if (experimentProject == null)
            {
                isToRefreshGridValue = false;
            }
            if (isToRefreshGridValue && experimentProject.CrossTalkValue == null)
            {
                experimentProject.CrossTalkValue = new double[channelCount, channelCount];
            }
            for (int i = 0; i < channelCount; i++)
            {
                dataTable.Columns.Add("Channel" + (i + 1), typeof(double));
            }
            for (int j = 0; j < channelCount; j++)
            {
                object[] array = new object[channelCount];
                for (int i = 0; i < array.Length; i++)
                {
                    if (isToRefreshGridValue)
                    {
                        array[i] = experimentProject.CrossTalkValue[j, i];
                    }
                    else
                    {
                        array[i] = 0;
                    }
                }
                dataTable.Rows.Add(array);
            }
            crossTalkGrid.UpdateMode = UpdateMode.OnUpdate;
            crossTalkGrid.DataSource = dataTable;
            crossTalkGrid.DisplayLayout.CaptionVisible = DefaultableBoolean.False;
            crossTalkGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select;
            crossTalkGrid.DisplayLayout.Override.HeaderStyle = HeaderStyle.WindowsXPCommand;
            crossTalkGrid.DisplayLayout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.SingleBand;
            crossTalkGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.Horizontal;
            crossTalkGrid.DisplayLayout.Override.ExpansionIndicator = ShowExpansionIndicator.Never;
            crossTalkGrid.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand;
            crossTalkGrid.DisplayLayout.Override.AllowAddNew = AllowAddNew.No;
            crossTalkGrid.DisplayLayout.Override.AllowColMoving = AllowColMoving.NotAllowed;
            crossTalkGrid.DisplayLayout.Override.AllowColSizing = AllowColSizing.None;
            crossTalkGrid.DisplayLayout.Override.AllowColSwapping = AllowColSwapping.NotAllowed;
            crossTalkGrid.DisplayLayout.Override.RowSizing = RowSizing.Fixed;
            crossTalkGrid.DisplayLayout.Scrollbars = Scrollbars.Both;
            crossTalkGrid.DisplayLayout.Override.RowSizing = RowSizing.AutoFixed;
            crossTalkGrid.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand;
            crossTalkGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.Horizontal;
            crossTalkGrid.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement;
            crossTalkGrid.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.RowIndex;
            crossTalkGrid.DisplayLayout.Override.RowSelectorWidth = 85;
            crossTalkGrid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
            crossTalkGrid.DisplayLayout.Override.CellDisplayStyle = CellDisplayStyle.FormattedText;
            crossTalkGrid.CreationFilter = new ShowCrossTalkGridTextInRowSelect(mResourceManager);
            foreach (UltraGridColumn column in crossTalkGrid.DisplayLayout.Bands[0].Columns)
            {
                if (isLocked)
                {
                    column.CellActivation = Activation.NoEdit;
                }
                column.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DoubleNonNegativeWithSpin;
                column.MaskInput = "nn.nn";
                column.PromptChar = ' ';
                column.Header.Appearance.TextHAlign = HAlign.Center;
                column.Header.Appearance.TextVAlign = VAlign.Middle;
                column.CellAppearance.TextHAlign = HAlign.Center;
                column.CellAppearance.TextVAlign = VAlign.Middle;
                column.MaxValue = mConfigurationService.MaxCrossTalkValue;
                column.Tag = column.Index;
            }
            if (isToRefreshGridValue)
            {
                return RefreshCrossTalkValueInGrid(experimentProject, crossTalkGrid);
            }
            return false;
        }

        public bool RefreshCrossTalkValueInGrid(IPcrExperimentProject experimentProject, UltraGrid crossTalkGrid)
        {
            int num = 0;
            int num2 = 0;
            IProjectItem[] projectItems = experimentProject.ProjectItems;
            foreach (IProjectItem projectItem in projectItems)
            {
                if (projectItem == null)
                {
                    crossTalkGrid.DisplayLayout.Bands[0].Columns[num2].Hidden = true;
                    crossTalkGrid.DisplayLayout.Rows[num2].Hidden = true;
                    num2++;
                    continue;
                }
                int position = projectItem.ChannelConfiguration.Position;
                crossTalkGrid.DisplayLayout.Bands[0].Columns[position].Header.Caption = mResourceManager.GetString("ChannelString") + " " + (position + 1);
                if (!projectItem.ChannelConfiguration.IsAvailable || !projectItem.ChannelConfiguration.IsSelected)
                {
                    crossTalkGrid.DisplayLayout.Bands[0].Columns[position].Hidden = true;
                    crossTalkGrid.DisplayLayout.Rows[position].Hidden = true;
                }
                else
                {
                    num++;
                    crossTalkGrid.DisplayLayout.Bands[0].Columns[position].Hidden = false;
                    crossTalkGrid.DisplayLayout.Rows[position].Hidden = false;
                    crossTalkGrid.DisplayLayout.Bands[0].Columns[position].Width = 80;
                    foreach (UltraGridCell cell in crossTalkGrid.DisplayLayout.Rows[position].Cells)
                    {
                        cell.SetValue(experimentProject.CrossTalkValue[position, cell.Column.Index], false);
                        if (position == cell.Column.Index)
                        {
                            cell.Activation = Activation.NoEdit;
                            cell.Appearance.BackColor = Color.LightGray;
                            cell.ActiveAppearance.BackColor = Color.LightGray;
                        }
                    }
                }
                num2++;
            }
            return num > 1;
        }

        private void InitializeProgramCurve(UltraChart chartProgram)
        {
            chartProgram.ChartType = ChartType.ScatterChart;
            chartProgram.ScatterChart.ConnectWithLines = true;
            chartProgram.ScatterChart.Icon = SymbolIcon.None;
            chartProgram.ScatterChart.IconSize = SymbolIconSize.Small;
            chartProgram.ScatterChart.LineAppearance.SplineTension = 0f;
            chartProgram.Axis.Y.RangeType = AxisRangeType.Custom;
            chartProgram.Axis.Y.RangeMax = mPcrProgramConfiguration.MaxTemperatureAxis;
            chartProgram.Axis.Y.RangeMin = mPcrProgramConfiguration.MinTemperatureAxis;
            chartProgram.Axis.Y.Visible = false;
            chartProgram.Axis.X.RangeType = AxisRangeType.Custom;
            chartProgram.Axis.X.RangeMax = 5.0;
            chartProgram.Axis.X.RangeMin = 0.0;
            chartProgram.Axis.X.Visible = false;
            chartProgram.Axis.X.ScrollScale.Visible = false;
        }

        protected void mItemGrid_RowColChange(object sender, RowColChangeEventArgs e)
        {
        }

        protected void mItemGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Return) || e.KeyCode.Equals(Keys.Tab))
            {
                mIsItemGridEnterKeyUp = true;
            }
            else
            {
                mIsItemGridEnterKeyUp = false;
            }
        }

        protected void mItemGrid_LeaveCell(object sender, LeaveCellEventArgs e)
        {
            try
            {
                Grid val = (Grid)((sender is Grid) ? sender : null);
                val.AutoRedraw = false;
                if (e.NewRow >= 3 && val.Rows > 4)
                {
                    val.Column(e.NewCol).CellType = (CellTypeEnum)1;
                    string text = val.Cell(e.NewRow, e.NewCol).Text.Trim();
                    val.ComboBox(e.NewCol).Items.Clear();
                    if (!string.IsNullOrEmpty(text))
                    {
                        val.ComboBox(e.NewCol).Items.Add(text);
                    }
                    if (!text.Equals("N/A"))
                    {
                        val.ComboBox(e.NewCol).Items.Add("N/A");
                    }
                }
                else
                {
                    val.Column(e.NewCol).CellType = (CellTypeEnum)6;
                }
                val.Column(e.Col).AutoFit();
                if (val.Column(e.Col).Width < 75)
                {
                    val.Column(e.Col).Width = 75;
                }
                val.AutoRedraw = true;
                val.Refresh();
                if (!mIsItemGridEnterKeyUp)
                {
                    return;
                }
                mIsItemGridEnterKeyUp = false;
                for (int i = e.NewRow; i < val.Rows; i++)
                {
                    int num = 1;
                    if (i == e.NewRow)
                    {
                        num = e.NewCol;
                    }
                    for (int j = num; j < val.Cols; j++)
                    {
                        if (!val.Cell(i, j).Locked)
                        {
                            e.Cancel = true;
                            val.Cell(i, j).SetFocus();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        protected void mAlleleItemGrid_CellChanging(object sender, CellChangingEventArgs e)
        {
            try
            {
                if (e.Col != 2)
                {
                    return;
                }
                Grid val = (Grid)((sender is Grid) ? sender : null);
                if (val.Cell(e.Row, e.Col).Text == " ")
                {
                    val.Cell(e.Row, 3).Text = string.Empty;
                    return;
                }
                IChannelConfiguration[] array = ((Control)(object)val).Tag as IChannelConfiguration[];
                if (array == null)
                {
                    return;
                }
                for (int i = 1; i < val.Rows; i++)
                {
                    if (i != e.Row && val.Cell(i, 2).Text.Equals(val.Cell(e.Row, e.Col).Text))
                    {
                        val.Cell(e.Row, e.Col).Text = " ";
                        MessageBox.Show(mResourceManager.GetString("ChannelNameEqual"), mResourceManager.GetString("ErrorString"));
                        return;
                    }
                }
                int result;
                if (int.TryParse(val.Cell(e.Row, e.Col).Text, out result) && result > 0 && result <= array.Length)
                {
                    val.Cell(e.Row, 3).Text = array[result - 1].Content;
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        private void RefreshAbosulteGridChannelStatus(Grid grid, int col, int row)
        {
            grid.AutoRedraw = false;
            for (int i = 3; i < grid.Rows; i++)
            {
                if (grid.Cell(row, col).BooleanValue)
                {
                    grid.Cell(i, col).ForeColor = Color.Black;
                    grid.Cell(i, col).BackColor = Color.White;
                    grid.Cell(i, col).Locked = false;
                }
                else
                {
                    grid.Cell(i, col).ForeColor = Color.WhiteSmoke;
                    grid.Cell(i, col).BackColor = Color.WhiteSmoke;
                    grid.Cell(i, col).Locked = true;
                }
            }
            grid.AutoRedraw = true;
        }

        private void RefreshGeneScanGridChannelStatus(Grid grid, int col)
        {
            //IL_000f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0019: Expected O, but got Unknown
            //IL_00d4: Unknown result type (might be due to invalid IL or missing references)
            //IL_00de: Expected O, but got Unknown
            grid.AutoRedraw = false;
            grid.CellChange -= new CellChangeEventHandler(mGeneScanItemGrid_CellChange);
            if (!grid.Cell(2, col).BooleanValue)
            {
                grid.Cell(2, col).Text = "1";
            }
            grid.Cell(3, col).Locked = false;
            grid.Cell(3, col).ForeColor = Color.Black;
            grid.Cell(3, col).BackColor = Color.White;
            for (int i = 1; i < grid.Cols; i++)
            {
                if (i != col)
                {
                    grid.Cell(2, i).Text = "0";
                    grid.Cell(3, i).Locked = true;
                    grid.Cell(3, i).ForeColor = Color.WhiteSmoke;
                    grid.Cell(3, i).BackColor = Color.WhiteSmoke;
                }
            }
            grid.AutoRedraw = true;
            grid.CellChange += new CellChangeEventHandler(mGeneScanItemGrid_CellChange);
        }

        protected void mItemGrid_CellChange(object sender, CellChangeEventArgs e)
        {
            try
            {
                if (e.Row == 2)
                {
                    Grid val = (Grid)((sender is Grid) ? sender : null);
                    RefreshAbosulteGridChannelStatus(val, e.Col, e.Row);
                    val.Cell(3, e.Col).SetFocus();
                    val.Refresh();
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        protected void mGeneScanItemGrid_CellChange(object sender, CellChangeEventArgs e)
        {
            try
            {
                if (e.Row == 2)
                {
                    Grid val = (Grid)((sender is Grid) ? sender : null);
                    RefreshGeneScanGridChannelStatus(val, e.Col);
                    val.Cell(3, e.Col).SetFocus();
                    val.Refresh();
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        public UltraTabControl GenerateRuleTabControl(bool isLocked)
        {
            UltraTabControl ultraTabControl = new UltraTabControl();
            UltraTabSharedControlsPage ultraTabSharedControlsPage = new UltraTabSharedControlsPage();
            UltraTabPageControl ultraTabPageControl = new UltraTabPageControl();
            UltraTabPageControl ultraTabPageControl2 = new UltraTabPageControl();
            ultraTabSharedControlsPage = new UltraTabSharedControlsPage();
            UltraTab ultraTab = new UltraTab();
            UltraTab ultraTab2 = new UltraTab();
            ultraTabPageControl.SuspendLayout();
            ((ISupportInitialize)ultraTabControl).BeginInit();
            ultraTabControl.SuspendLayout();
            ultraTabPageControl.Location = new Point(1, 20);
            ultraTabPageControl.Name = "tabPageRuleControl";
            ultraTabPageControl.Size = new Size(839, 256);
            ultraTabPageControl2.Enabled = true;
            ultraTabPageControl2.Location = new Point(-10000, -10000);
            ultraTabPageControl2.Name = "TabPageAdvancedRuleControl";
            ultraTabPageControl2.Size = new Size(839, 256);
            ultraTabControl.CloseButtonLocation = TabCloseButtonLocation.None;
            ultraTabControl.Controls.Add(ultraTabSharedControlsPage);
            ultraTabControl.Controls.Add(ultraTabPageControl);
            ultraTabControl.Controls.Add(ultraTabPageControl2);
            ultraTabControl.Dock = DockStyle.Fill;
            ultraTabControl.Location = new Point(0, 0);
            ultraTabControl.Name = "ultraTabRule";
            ultraTabControl.SharedControlsPage = ultraTabSharedControlsPage;
            ultraTabControl.Size = new Size(841, 277);
            ultraTabControl.Style = UltraTabControlStyle.Excel;
            ultraTabControl.TabIndex = 3;
            ultraTab.AllowClosing = DefaultableBoolean.False;
            ultraTab.AllowMoving = DefaultableBoolean.False;
            ultraTab.CloseButtonVisibility = TabCloseButtonVisibility.Never;
            ultraTab.Key = "Rule";
            ultraTab.TabPage = ultraTabPageControl;
            ultraTab.Text = mResourceManager.GetString("RuleString");
            ultraTab2.AllowClosing = DefaultableBoolean.False;
            ultraTab2.AllowMoving = DefaultableBoolean.False;
            ultraTab2.CloseButtonVisibility = TabCloseButtonVisibility.Never;
            ultraTab2.Key = "AdvancedRule";
            ultraTab2.TabPage = ultraTabPageControl2;
            ultraTab2.Text = mResourceManager.GetString("AdvancedRuleString");
            ultraTabControl.Tabs.AddRange(new UltraTab[2] { ultraTab, ultraTab2 });
            ultraTab2.Visible = true;
            ultraTabSharedControlsPage.Location = new Point(-10000, -10000);
            ultraTabSharedControlsPage.Name = "tabSharedControlsPage";
            ultraTabSharedControlsPage.Size = new Size(839, 256);
            UltraGrid ultraGrid = GenerateSimpleRuleGrid(isLocked);
            Panel panel = GenerateRuleOptionPanel(isLocked);
            panel.Name = "basicRuleOptionPanel";
            ultraTabPageControl.Controls.Add(panel);
            ultraTabPageControl.Controls.Add(ultraGrid);
            panel.SendToBack();
            ultraGrid.BringToFront();
            Panel panel2 = new Panel();
            Panel panel3 = GenerateRuleOptionPanel(isLocked);
            panel3.Name = "advancedRuleOptionPanel";
            panel2.Dock = DockStyle.Fill;
            mRuleEditorService.DisplayRuleForm(panel2, isLocked);
            panel2.Name = "advancedRulePanel";
            ultraTabPageControl2.Controls.Add(panel3);
            ultraTabPageControl2.Controls.Add(panel2);
            panel3.SendToBack();
            panel2.BringToFront();
            CheckBox checkBox = panel.Controls[0] as CheckBox;
            CheckBox checkBox2 = panel3.Controls[0] as CheckBox;
            checkBox.Text = mResourceManager.GetString("UseBasicRuleString");
            checkBox2.Text = mResourceManager.GetString("UseAdvancedRuleString");
            checkBox.Tag = checkBox2;
            checkBox2.Tag = checkBox;
            checkBox.Checked = true;
            checkBox2.Checked = false;
            SetSimpleRuleEnabled(checkBox);
            SetAdvancedRuleEnabled(checkBox2);
            checkBox.CheckedChanged += chkSimpleRule_CheckedChanged;
            checkBox2.CheckedChanged += chkAdvancedRule_CheckedChanged;
            checkBox.Enabled = !isLocked;
            checkBox2.Enabled = !isLocked;
            ultraTabControl.ResumeLayout();
            ((ISupportInitialize)ultraTabControl).EndInit();
            ultraTabPageControl.ResumeLayout();
            return ultraTabControl;
        }

        private Panel GenerateRuleOptionPanel(bool isLocked)
        {
            Panel panel = new Panel();
            panel.Dock = DockStyle.Top;
            panel.Size = new Size(100, 32);
            CheckBox checkBox = new CheckBox();
            checkBox.Checked = true;
            checkBox.AutoSize = true;
            checkBox.Location = new Point(20, 8);
            panel.Controls.Add(checkBox);
            return panel;
        }

        private UltraGrid GenerateSimpleRuleGrid(bool isLocked)
        {
            Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
            new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
            UltraGrid ultraGrid = new UltraGrid();
            ((ISupportInitialize)ultraGrid).BeginInit();
            appearance.BackColor = SystemColors.Window;
            appearance.BorderColor = SystemColors.InactiveCaption;
            ultraGrid.DisplayLayout.Appearance = appearance;
            ultraGrid.DisplayLayout.BorderStyle = UIElementBorderStyle.Solid;
            ultraGrid.DisplayLayout.CaptionVisible = DefaultableBoolean.False;
            appearance2.BackColor = SystemColors.ActiveBorder;
            appearance2.BackColor2 = SystemColors.ControlDark;
            appearance2.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
            appearance2.BorderColor = SystemColors.Window;
            ultraGrid.DisplayLayout.GroupByBox.Appearance = appearance2;
            appearance3.ForeColor = SystemColors.GrayText;
            ultraGrid.DisplayLayout.GroupByBox.BandLabelAppearance = appearance3;
            ultraGrid.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.Solid;
            appearance4.BackColor = SystemColors.ControlLightLight;
            appearance4.BackColor2 = SystemColors.Control;
            appearance4.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
            appearance4.ForeColor = SystemColors.GrayText;
            ultraGrid.DisplayLayout.GroupByBox.PromptAppearance = appearance4;
            ultraGrid.DisplayLayout.MaxColScrollRegions = 1;
            ultraGrid.DisplayLayout.MaxRowScrollRegions = 1;
            appearance5.BackColor = SystemColors.Window;
            appearance5.ForeColor = SystemColors.ControlText;
            ultraGrid.DisplayLayout.Override.ActiveCellAppearance = appearance5;
            ultraGrid.DisplayLayout.Override.BorderStyleCell = UIElementBorderStyle.Dotted;
            ultraGrid.DisplayLayout.Override.BorderStyleRow = UIElementBorderStyle.Dotted;
            appearance6.BackColor = SystemColors.Window;
            ultraGrid.DisplayLayout.Override.CardAreaAppearance = appearance6;
            appearance7.BorderColor = Color.Silver;
            appearance7.TextTrimming = TextTrimming.EllipsisCharacter;
            ultraGrid.DisplayLayout.Override.CellAppearance = appearance7;
            ultraGrid.DisplayLayout.Override.CellClickAction = CellClickAction.EditAndSelectText;
            ultraGrid.DisplayLayout.Override.CellPadding = 0;
            appearance8.BackColor = SystemColors.Control;
            appearance8.BackColor2 = SystemColors.ControlDark;
            appearance8.BackGradientAlignment = GradientAlignment.Element;
            appearance8.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
            appearance8.BorderColor = SystemColors.Window;
            ultraGrid.DisplayLayout.Override.GroupByRowAppearance = appearance8;
            appearance9.TextHAlignAsString = "Left";
            ultraGrid.DisplayLayout.Override.HeaderAppearance = appearance9;
            ultraGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortMulti;
            ultraGrid.DisplayLayout.Override.HeaderStyle = HeaderStyle.WindowsXPCommand;
            appearance10.BackColor = SystemColors.Window;
            appearance10.BorderColor = Color.Silver;
            ultraGrid.DisplayLayout.Override.RowAppearance = appearance10;
            ultraGrid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
            appearance11.BackColor = SystemColors.ControlLight;
            ultraGrid.DisplayLayout.Override.TemplateAddRowAppearance = appearance11;
            ultraGrid.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;
            ultraGrid.DisplayLayout.ScrollStyle = ScrollStyle.Immediate;
            ultraGrid.DisplayLayout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.SingleBand;
            ultraGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
            ultraGrid.Dock = DockStyle.Fill;
            ultraGrid.Location = new Point(0, 0);
            ultraGrid.Name = "grdRule";
            ultraGrid.Size = new Size(839, 256);
            ultraGrid.TabIndex = 0;
            ultraGrid.Text = "Rule";
            new DataTable();
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("TubeID", "TubeID");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("ProjectItem", "ProjectItem");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("Channel", "Channel");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("TargetIndex", "TargetIndex");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("QuantitativeThreshold", "QuantitativeThreshold");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("SetQuantitativeGreyZone", "SetQuantitativeGreyZone");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("QuantitativeGreyZone", "QuantitativeGreyZone");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("QualitativeThreshold", "QualitativeThreshold");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("SetQualitativeGreyZone", "SetQualitativeGreyZone");
            ultraGrid.DisplayLayout.Bands[0].Columns.Add("QualitativeGreyZone", "QualitativeGreyZone");
            ultraGrid.DisplayLayout.Bands[0].Columns["TubeID"].DataType = typeof(int);
            ultraGrid.DisplayLayout.Bands[0].Columns["ProjectItem"].DataType = typeof(string);
            ultraGrid.DisplayLayout.Bands[0].Columns["Channel"].DataType = typeof(int);
            ultraGrid.DisplayLayout.Bands[0].Columns["TargetIndex"].DataType = typeof(int);
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeThreshold"].DataType = typeof(double);
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].DataType = typeof(bool);
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].DataType = typeof(double);
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeThreshold"].DataType = typeof(double);
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].DataType = typeof(bool);
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].DataType = typeof(double);
            ultraGrid.UpdateMode = UpdateMode.OnUpdate;
            ultraGrid.DisplayLayout.CaptionVisible = DefaultableBoolean.False;
            ultraGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select;
            ultraGrid.DisplayLayout.Override.HeaderStyle = HeaderStyle.WindowsXPCommand;
            ultraGrid.DisplayLayout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.SingleBand;
            ultraGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.Horizontal;
            ultraGrid.DisplayLayout.Override.ExpansionIndicator = ShowExpansionIndicator.Never;
            ultraGrid.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand;
            ultraGrid.DisplayLayout.Override.AllowAddNew = AllowAddNew.No;
            ultraGrid.DisplayLayout.Override.AllowColMoving = AllowColMoving.NotAllowed;
            ultraGrid.DisplayLayout.Override.AllowColSizing = AllowColSizing.None;
            ultraGrid.DisplayLayout.Override.AllowColSwapping = AllowColSwapping.NotAllowed;
            ultraGrid.DisplayLayout.Override.RowSizing = RowSizing.Fixed;
            ultraGrid.DisplayLayout.Scrollbars = Scrollbars.Both;
            ultraGrid.DisplayLayout.Override.RowSizing = RowSizing.AutoFixed;
            ultraGrid.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand;
            ultraGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.Horizontal;
            ultraGrid.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement;
            ultraGrid.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.RowIndex;
            ultraGrid.DisplayLayout.Override.RowSelectorWidth = 80;
            ultraGrid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
            ultraGrid.DisplayLayout.Override.CellDisplayStyle = CellDisplayStyle.FormattedText;
            UltraGridGroup[] array = new UltraGridGroup[3]
            {
                new UltraGridGroup("Target", 0),
                null,
                null
            };
            array[0].Header.Caption = mResourceManager.GetString("TargetString");
            array[0].Hidden = false;
            array[0].Header.Appearance.TextHAlign = HAlign.Center;
            array[0].Header.Appearance.TextVAlign = VAlign.Middle;
            array[1] = new UltraGridGroup("Quantitative", 1);
            array[1].Header.Caption = mResourceManager.GetString("QuantitativeString");
            array[1].Header.Appearance.TextHAlign = HAlign.Center;
            array[1].Header.Appearance.TextVAlign = VAlign.Middle;
            array[2] = new UltraGridGroup("Qualitative", 2);
            array[2].Header.Caption = mResourceManager.GetString("QualitativeString");
            array[2].Header.Appearance.TextHAlign = HAlign.Center;
            array[2].Header.Appearance.TextVAlign = VAlign.Middle;
            ultraGrid.DisplayLayout.Override.HeaderCheckBoxVisibility = HeaderCheckBoxVisibility.WhenUsingCheckEditor;
            ultraGrid.DisplayLayout.Override.CellDisplayStyle = CellDisplayStyle.FullEditorDisplay;
            ultraGrid.DisplayLayout.Bands[0].Groups.AddRange(array);
            ultraGrid.DisplayLayout.Bands[0].Columns["TubeID"].Group = array[0];
            ultraGrid.DisplayLayout.Bands[0].Columns["TubeID"].Header.Caption = mResourceManager.GetString("TubeIDString");
            ultraGrid.DisplayLayout.Bands[0].Columns["ProjectItem"].Group = array[0];
            ultraGrid.DisplayLayout.Bands[0].Columns["ProjectItem"].Header.Caption = mResourceManager.GetString("NameString");
            ultraGrid.DisplayLayout.Bands[0].Columns["TargetIndex"].Group = array[0];
            ultraGrid.DisplayLayout.Bands[0].Columns["TargetIndex"].Hidden = true;
            ultraGrid.DisplayLayout.Bands[0].Columns["Channel"].Group = array[0];
            ultraGrid.DisplayLayout.Bands[0].Columns["Channel"].Hidden = true;
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].Hidden = true;
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].Hidden = true;
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeThreshold"].Group = array[1];
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeThreshold"].Header.Caption = mResourceManager.GetString("NegativeThresholdString");
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].Group = array[1];
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].Header.Caption = mResourceManager.GetString("SetGreyZoneString");
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].Group = array[1];
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].Header.Caption = mResourceManager.GetString("GrayZoneThresholdString");
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeThreshold"].Group = array[2];
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeThreshold"].Header.Caption = mResourceManager.GetString("NegativeThresholdString");
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].Group = array[2];
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].Header.Caption = mResourceManager.GetString("SetGreyZoneString");
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].Group = array[2];
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].Header.Caption = mResourceManager.GetString("GrayZoneThresholdString");
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always;
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQuantitativeGreyZone"].SetHeaderCheckedState(ultraGrid.Rows, true);
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always;
            ultraGrid.DisplayLayout.Bands[0].Columns["SetQualitativeGreyZone"].SetHeaderCheckedState(ultraGrid.Rows, true);
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always;
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].SetHeaderCheckedState(ultraGrid.Rows, true);
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always;
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].SetHeaderCheckedState(ultraGrid.Rows, true);
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeThreshold"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeThreshold"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeThreshold"].MaskInput = "nnnnnnnnnnnnnnnn";
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeThreshold"].Width = 130;
            ultraGrid.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].MaskInput = "nnnnnnnnnnnnnnnn";
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeThreshold"].MaskInput = "nn";
            ultraGrid.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].MaskInput = "nn";
            foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
            {
                if (isLocked)
                {
                    column.CellActivation = Activation.NoEdit;
                }
                column.Header.Appearance.TextHAlign = HAlign.Center;
                column.Header.Appearance.TextVAlign = VAlign.Middle;
                column.CellAppearance.TextHAlign = HAlign.Center;
                column.CellAppearance.TextVAlign = VAlign.Middle;
                column.PromptChar = ' ';
            }
            ultraGrid.AfterHeaderCheckStateChanged += grdRule_AfterHeaderCheckStateChanged;
            ultraGrid.BeforeHeaderCheckStateChanged += grdRule_BeforeHeaderCheckStateChanged;
            ultraGrid.DoubleClickHeader += grdRule_DoubleClickHeader;
            ((ISupportInitialize)ultraGrid).EndInit();
            return ultraGrid;
        }

        private void SetSimpleRuleEnabled(CheckBox chkSimpleRule)
        {
            CheckBox checkBox = chkSimpleRule.Tag as CheckBox;
            UltraTabPageControl ultraTabPageControl = chkSimpleRule.Parent.Parent as UltraTabPageControl;
            ultraTabPageControl.Controls["grdRule"].Enabled = chkSimpleRule.Checked;
            IPcrExperimentProject pcrExperimentProject = chkSimpleRule.Parent.Tag as IPcrExperimentProject;
            if (pcrExperimentProject != null)
            {
                pcrExperimentProject.IsUseAdvancedRule = checkBox.Checked;
            }
        }

        private void SetAdvancedRuleEnabled(CheckBox chkAdvancedRule)
        {
            UltraTabPageControl ultraTabPageControl = chkAdvancedRule.Parent.Parent as UltraTabPageControl;
            ultraTabPageControl.Controls["advancedRulePanel"].Enabled = chkAdvancedRule.Checked;
            IPcrExperimentProject pcrExperimentProject = chkAdvancedRule.Parent.Tag as IPcrExperimentProject;
            if (pcrExperimentProject != null)
            {
                pcrExperimentProject.IsUseAdvancedRule = chkAdvancedRule.Checked;
            }
        }

        private void chkSimpleRule_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            CheckBox checkBox2 = checkBox.Tag as CheckBox;
            checkBox.CheckedChanged -= chkSimpleRule_CheckedChanged;
            checkBox2.CheckedChanged -= chkAdvancedRule_CheckedChanged;
            if (!checkBox.Checked)
            {
                checkBox.Checked = true;
            }
            else
            {
                checkBox2.Checked = false;
                SetSimpleRuleEnabled(checkBox);
                SetAdvancedRuleEnabled(checkBox2);
            }
            checkBox.CheckedChanged += chkSimpleRule_CheckedChanged;
            checkBox2.CheckedChanged += chkAdvancedRule_CheckedChanged;
        }

        private void chkAdvancedRule_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            CheckBox checkBox2 = checkBox.Tag as CheckBox;
            checkBox2.CheckedChanged -= chkSimpleRule_CheckedChanged;
            checkBox.CheckedChanged -= chkAdvancedRule_CheckedChanged;
            if (!checkBox.Checked)
            {
                checkBox.Checked = true;
            }
            else
            {
                checkBox2.Checked = false;
                SetSimpleRuleEnabled(checkBox2);
                SetAdvancedRuleEnabled(checkBox);
            }
            checkBox2.CheckedChanged += chkSimpleRule_CheckedChanged;
            checkBox.CheckedChanged += chkAdvancedRule_CheckedChanged;
        }

        private void RefreshGridGreyZoneDisplay(bool isChecked, UltraGrid grid, UltraGridColumn column)
        {
            grid.AfterHeaderCheckStateChanged -= grdRule_AfterHeaderCheckStateChanged;
            grid.BeforeHeaderCheckStateChanged -= grdRule_BeforeHeaderCheckStateChanged;
            column.SetHeaderCheckedState(grid.Rows, isChecked);
            foreach (UltraGridRow row in grid.Rows)
            {
                if (isChecked)
                {
                    row.Cells[column].Activation = Activation.AllowEdit;
                    row.Cells[column].Appearance.BackColor = Color.White;
                }
                else
                {
                    row.Cells[column].Activation = Activation.Disabled;
                    row.Cells[column].Appearance.BackColor = Color.LightGray;
                }
            }
            grid.BeforeHeaderCheckStateChanged += grdRule_BeforeHeaderCheckStateChanged;
            grid.AfterHeaderCheckStateChanged += grdRule_AfterHeaderCheckStateChanged;
        }

        private void grdRule_BeforeHeaderCheckStateChanged(object sender, BeforeHeaderCheckStateChangedEventArgs e)
        {
            try
            {
                if (e.Column.CellActivation == Activation.NoEdit)
                {
                    e.Cancel = true;
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        private void grdRule_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e)
        {
            try
            {
                if (e.Header.Column == null)
                {
                    return;
                }
                UltraGrid ultraGrid = (UltraGrid)sender;
                IPcrExperimentProject pcrExperimentProject = ultraGrid.Tag as IPcrExperimentProject;
                if (pcrExperimentProject == null)
                {
                    return;
                }
                if (e.Header.Column.Key.Equals("QuantitativeGreyZone") || e.Header.Column.Key.Equals("QuantitativeThreshold"))
                {
                    if (string.IsNullOrEmpty(pcrExperimentProject.QuantitativeGreyConlusion))
                    {
                        pcrExperimentProject.QuantitativeGreyConlusion = mResourceManager.GetString("DefaultGreyConclusionString");
                    }
                    if (string.IsNullOrEmpty(pcrExperimentProject.QuantitativePositiveConlusion))
                    {
                        pcrExperimentProject.QuantitativePositiveConlusion = mResourceManager.GetString("DefaultPositiveConclusionString");
                    }
                    if (string.IsNullOrEmpty(pcrExperimentProject.QuantitativeNegativeConlusion))
                    {
                        pcrExperimentProject.QuantitativeNegativeConlusion = mResourceManager.GetString("DefaultNegativeConclusionString");
                    }
                    FormGreyZoneConclusion formGreyZoneConclusion = new FormGreyZoneConclusion(mResourceManager.GetString("QuantitativeConclusionString"), new string[3] { pcrExperimentProject.QuantitativeNegativeConlusion, pcrExperimentProject.QuantitativePositiveConlusion, pcrExperimentProject.QuantitativeGreyConlusion }, new Color[3] { pcrExperimentProject.QuantitativeNegativeColor, pcrExperimentProject.QuantitativePositiveColor, pcrExperimentProject.QuantitativeGreyColor });
                    if (formGreyZoneConclusion.ShowDialog() == DialogResult.OK)
                    {
                        pcrExperimentProject.QuantitativeGreyConlusion = formGreyZoneConclusion.GetGrayZoneConclusion();
                        pcrExperimentProject.QuantitativePositiveConlusion = formGreyZoneConclusion.GetPositiveConclusion();
                        pcrExperimentProject.QuantitativeNegativeConlusion = formGreyZoneConclusion.GetNegativeConclusion();
                        pcrExperimentProject.QuantitativeGreyColor = formGreyZoneConclusion.GetGrayZoneColor();
                        pcrExperimentProject.QuantitativePositiveColor = formGreyZoneConclusion.GetPositiveColor();
                        pcrExperimentProject.QuantitativeNegativeColor = formGreyZoneConclusion.GetNegativeColor();
                    }
                }
                else if (e.Header.Column.Key.Equals("QualitativeGreyZone") || e.Header.Column.Key.Equals("QualitativeThreshold"))
                {
                    if (string.IsNullOrEmpty(pcrExperimentProject.QualitativeGreyConlusion))
                    {
                        pcrExperimentProject.QualitativeGreyConlusion = mResourceManager.GetString("DefaultGreyConclusionString");
                    }
                    if (string.IsNullOrEmpty(pcrExperimentProject.QualitativePositiveConlusion))
                    {
                        pcrExperimentProject.QualitativePositiveConlusion = mResourceManager.GetString("DefaultPositiveConclusionString");
                    }
                    if (string.IsNullOrEmpty(pcrExperimentProject.QualitativeNegativeConlusion))
                    {
                        pcrExperimentProject.QualitativeNegativeConlusion = mResourceManager.GetString("DefaultNegativeConclusionString");
                    }
                    FormGreyZoneConclusion formGreyZoneConclusion2 = new FormGreyZoneConclusion(mResourceManager.GetString("QualitativeConclusionString"), new string[3] { pcrExperimentProject.QualitativeNegativeConlusion, pcrExperimentProject.QualitativePositiveConlusion, pcrExperimentProject.QualitativeGreyConlusion }, new Color[3] { pcrExperimentProject.QualitativeNegativeColor, pcrExperimentProject.QualitativePositiveColor, pcrExperimentProject.QualitativeGreyColor });
                    if (formGreyZoneConclusion2.ShowDialog() == DialogResult.OK)
                    {
                        pcrExperimentProject.QualitativeGreyConlusion = formGreyZoneConclusion2.GetGrayZoneConclusion();
                        pcrExperimentProject.QualitativePositiveConlusion = formGreyZoneConclusion2.GetPositiveConclusion();
                        pcrExperimentProject.QualitativeNegativeConlusion = formGreyZoneConclusion2.GetNegativeConclusion();
                        pcrExperimentProject.QualitativeGreyColor = formGreyZoneConclusion2.GetGrayZoneColor();
                        pcrExperimentProject.QualitativePositiveColor = formGreyZoneConclusion2.GetPositiveColor();
                        pcrExperimentProject.QualitativeNegativeColor = formGreyZoneConclusion2.GetNegativeColor();
                    }
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        private void grdRule_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)
        {
            try
            {
                UltraGrid ultraGrid = sender as UltraGrid;
                if (e.Column.CellActivation != Activation.Disabled)
                {
                    bool isChecked = e.Column.GetHeaderCheckedState(ultraGrid.Rows) == CheckState.Checked;
                    RefreshGridGreyZoneDisplay(isChecked, ultraGrid, e.Column);
                }
            }
            catch (Exception ex)
            {
                mPcrLogService.ShowExceptionDialogBox(ex);
            }
        }

        public bool RefreshRuleGrid(UltraGrid grdRule, IPcrExperimentProject pcrExperimentProject)
        {
            bool flag = true;
            bool flag2 = true;
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("TubeID", typeof(int));
            dataTable.Columns.Add("ProjectItem", typeof(string));
            dataTable.Columns.Add("Channel", typeof(int));
            dataTable.Columns.Add("TargetIndex", typeof(int));
            dataTable.Columns.Add("QuantitativeThreshold", typeof(double));
            dataTable.Columns.Add("SetQuantitativeGreyZone", typeof(bool));
            dataTable.Columns.Add("QuantitativeGreyZone", typeof(double));
            dataTable.Columns.Add("QualitativeThreshold", typeof(double));
            dataTable.Columns.Add("SetQualitativeGreyZone", typeof(bool));
            dataTable.Columns.Add("QualitativeGreyZone", typeof(double));
            List<IProjectItem> list = new List<IProjectItem>();
            if (pcrExperimentProject != null)
            {
                IProjectItem[] projectItems = pcrExperimentProject.ProjectItems;
                foreach (IProjectItem projectItem in projectItems)
                {
                    int num = 0;
                    if (projectItem == null || !projectItem.ChannelConfiguration.IsAvailable || !projectItem.ChannelConfiguration.IsSelected)
                    {
                        continue;
                    }
                    foreach (IAnalysisParameterConfiguration item in projectItem.TubeAnalysisParameterConfiguration)
                    {
                        object[] array = new object[10]
                        {
                            num + 1,
                            item.ProjectName,
                            projectItem.ChannelConfiguration.Position,
                            item.TargetIndex,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null
                        };
                        IAbsoluteProjectProperty absoluteProjectProperty = item.ProjectProperty as IAbsoluteProjectProperty;
                        if (absoluteProjectProperty == null)
                        {
                            absoluteProjectProperty = mConfigurationService.CreateAbsoluteProjectProperty(item.ProjectName, string.Empty, mConfigurationService.QuantitativeThreshold, mConfigurationService.QualitativeThreshold, mConfigurationService.QualitativeResultUnit, mConfigurationService.QuantitativeResultUnit, false, false, 0.0, 0.0) as IAbsoluteProjectProperty;
                            item.ProjectProperty = absoluteProjectProperty as IProjectProperty;
                        }
                        array[4] = absoluteProjectProperty.QuantitativeThreshold;
                        array[5] = absoluteProjectProperty.IsSetQuantitativeGreyZone;
                        array[6] = absoluteProjectProperty.QuantitativeGreyZone;
                        array[7] = absoluteProjectProperty.QualitativeThreshold;
                        array[8] = absoluteProjectProperty.IsSetQualitativeGreyZone;
                        array[9] = absoluteProjectProperty.QualitativeGreyZone;
                        list.Add(projectItem);
                        dataTable.Rows.Add(array);
                        if (!absoluteProjectProperty.IsSetQuantitativeGreyZone)
                        {
                            flag = false;
                        }
                        if (!absoluteProjectProperty.IsSetQualitativeGreyZone)
                        {
                            flag2 = false;
                        }
                        num++;
                    }
                }
            }
            grdRule.DataSource = dataTable;
            grdRule.Tag = pcrExperimentProject;
            foreach (UltraGridRow row in grdRule.Rows)
            {
                row.Tag = list[row.Index];
                row.Hidden |= row.Cells[1].Text.Equals("N/A");
            }
            grdRule.DisplayLayout.Bands[0].Columns["TubeID"].Hidden = pcrExperimentProject.TubeCount == 1;
            grdRule.DisplayLayout.Bands[0].Columns["TargetIndex"].Hidden = true;
            grdRule.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].SetHeaderCheckedState(grdRule.Rows, flag);
            grdRule.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].SetHeaderCheckedState(grdRule.Rows, flag2);
            grdRule.DisplayLayout.Bands[0].Columns["TubeID"].SortIndicator = SortIndicator.Ascending;
            grdRule.DisplayLayout.Bands[0].Columns["TubeID"].MergedCellStyle = MergedCellStyle.Always;
            grdRule.DisplayLayout.Bands[0].Columns["TubeID"].CellActivation = Activation.NoEdit;
            grdRule.DisplayLayout.Bands[0].Columns["ProjectItem"].CellActivation = Activation.NoEdit;
            RefreshGridGreyZoneDisplay(flag, grdRule, grdRule.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"]);
            RefreshGridGreyZoneDisplay(flag2, grdRule, grdRule.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"]);
            Panel panel = (Panel)grdRule.Parent;
            CheckBox checkBox = (CheckBox)panel.Controls[1].Controls[0];
            panel.Tag = pcrExperimentProject;
            CheckBox checkBox2 = (CheckBox)checkBox.Tag;
            Panel panel2 = (Panel)checkBox2.Parent;
            panel2.Tag = pcrExperimentProject;
            checkBox.Checked = !pcrExperimentProject.IsUseAdvancedRule;
            checkBox2.Checked = pcrExperimentProject.IsUseAdvancedRule;
            SetSimpleRuleEnabled(checkBox);
            SetAdvancedRuleEnabled(checkBox2);
            return true;
        }

        public bool SaveRuleGrid(UltraGrid grdRule, IPcrExperimentProject pcrExperimentProject)
        {
            bool flag = grdRule.DisplayLayout.Bands[0].Columns["QuantitativeGreyZone"].GetHeaderCheckedState(grdRule.Rows) == CheckState.Checked;
            bool flag2 = grdRule.DisplayLayout.Bands[0].Columns["QualitativeGreyZone"].GetHeaderCheckedState(grdRule.Rows) == CheckState.Checked;
            foreach (UltraGridRow row in grdRule.Rows)
            {
                IProjectItem projectItem = row.Tag as IProjectItem;
                if (projectItem == null)
                {
                    continue;
                }
                int num = Convert.ToInt32(row.Cells["TargetIndex"].Text);
                if (num > projectItem.TubeAnalysisParameterConfiguration.Count)
                {
                    break;
                }
                int position = projectItem.ChannelConfiguration.Position;
                IAbsoluteProjectProperty absoluteProjectProperty = projectItem.TubeAnalysisParameterConfiguration[num].ProjectProperty as IAbsoluteProjectProperty;
                if (absoluteProjectProperty == null)
                {
                    continue;
                }
                double result = 0.0;
                double result2 = 0.0;
                double result3 = 0.0;
                double result4 = 0.0;
                if (row.Hidden)
                {
                    absoluteProjectProperty.IsSetQualitativeGreyZone = flag2;
                    absoluteProjectProperty.IsSetQuantitativeGreyZone = flag;
                    absoluteProjectProperty.QualitativeGreyZone = result4;
                    absoluteProjectProperty.QuantitativeGreyZone = result3;
                    absoluteProjectProperty.QualitativeThreshold = result2;
                    absoluteProjectProperty.QuantitativeThreshold = result;
                    continue;
                }
                if (!double.TryParse(row.Cells["QuantitativeThreshold"].Text, out result))
                {
                    MessageBox.Show(mResourceManager.GetString("QuantitativeThresholdEmpty"), mResourceManager.GetString("ErrorString"));
                    row.Cells["QuantitativeThreshold"].Activate();
                    grdRule.PerformAction(UltraGridAction.EnterEditMode);
                    return false;
                }
                if (!double.TryParse(row.Cells["QualitativeThreshold"].Text, out result2))
                {
                    MessageBox.Show(mResourceManager.GetString("QualitativeeThresholdEmpty"), mResourceManager.GetString("ErrorString"));
                    row.Cells["QualitativeThreshold"].Activate();
                    grdRule.PerformAction(UltraGridAction.EnterEditMode);
                    return false;
                }
                if (flag)
                {
                    if (!double.TryParse(row.Cells["QuantitativeGreyZone"].Text, out result3))
                    {
                        MessageBox.Show(mResourceManager.GetString("GrayZoneThresholdEmpty"), mResourceManager.GetString("ErrorString"));
                        row.Cells["QuantitativeGreyZone"].Activate();
                        return false;
                    }
                    if (result3 <= result)
                    {
                        MessageBox.Show(mResourceManager.GetString("QuantitativeGrayZoneThresholdRange"), mResourceManager.GetString("ErrorString"));
                        row.Cells["QuantitativeGreyZone"].Activate();
                        grdRule.PerformAction(UltraGridAction.EnterEditMode);
                        return false;
                    }
                }
                if (flag2)
                {
                    if (!double.TryParse(row.Cells["QualitativeGreyZone"].Text, out result4))
                    {
                        MessageBox.Show(mResourceManager.GetString("GrayZoneThresholdEmpty"), mResourceManager.GetString("ErrorString"));
                        row.Cells["QualitativeGreyZone"].Activate();
                        grdRule.PerformAction(UltraGridAction.EnterEditMode);
                        return false;
                    }
                    if (result4 >= result2)
                    {
                        MessageBox.Show(mResourceManager.GetString("QualitativeGrayZoneThresholdRange"), mResourceManager.GetString("ErrorString"));
                        row.Cells["QualitativeGreyZone"].Activate();
                        grdRule.PerformAction(UltraGridAction.EnterEditMode);
                        return false;
                    }
                }
                absoluteProjectProperty.QuantitativeThreshold = result;
                absoluteProjectProperty.QualitativeThreshold = result2;
                absoluteProjectProperty.QuantitativeGreyZone = result3;
                absoluteProjectProperty.QualitativeGreyZone = result4;
                absoluteProjectProperty.IsSetQuantitativeGreyZone = flag;
                absoluteProjectProperty.IsSetQualitativeGreyZone = flag2;
            }
            return true;
        }
    }
}
